我对RESTful api感到困惑. 码:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.*
import static groovyx.net.http.ContentType.JSON
import org.codehaus.groovy.grails.web.json.JSONObject
def isMailer = new HTTPBuilder( 'http://mailer-api.com' )
isMailer.request( GET, JSON ) {
uri.path = '/is/mail/rest/json/' + token
isMailer.auth.basic 'ddd', 'aaa'
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
response.success = { resp, json ->
// response handler for a success response code:
System.out << json
if(json.has("DISP_NAME")) {
println "************************"
res = "Yes"
} else if (json.has("ListError")) {
res = "No"
}
}
}
// handler for any failure status code: …Run Code Online (Sandbox Code Playgroud)