我需要使用 Groovy HTTP Builder 更新 Zendesk 票证。我使用以下代码
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )
import java.util.Properties;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import groovyx.net.http.*;
import static groovyx.net.http.Method.*;
import groovy.json.*;
import groovyx.net.http.ContentType;
def jsonBuilder = new groovy.json.JsonBuilder();
class MyTicket
{
def subject
}
def myTicket = new MyTicket(
subject: 'xyz'.toString()
)
def ticketList=[myTicket]
jsonBuilder(ticket:ticketList)
println(jsonBuilder)
def authSite = new HTTPBuilder('https://{subdomain}.zendesk.com/api/v2/tickets/{ticketid}.json');
authSite.auth.basic 'username', 'password';
authSite.request( Method.PUT, ContentType.JSON )
{ req ->
uri.path = ''https://{subdomain}.zendesk.com/api/v2/tickets/{ticketid}.json'';
requestContentType = ContentType.JSON;
headers.Accept = 'application/json';
body =[jsonBuilder]
response.success = { resp, reader->
reader.ticket.subject;
}
}
但是票没有更新。有没有一种执行方法。请建议我哪里出错了。