groovy @Grab ('org.codehaus.groovy.modules.http-builder:http-builder:0.7.1') import groovyx.net.http.* import static groovyx.net.http.ContentType.* import static groovyx.net.http.Method.* def http = new HTTPBuilder('http://api.example.com') http.request(GET, JSON) { uri.path = '/users' headers.Accept = 'application/json' response.success = { resp, json -> println "Received response status: ${resp.statusLine}" println "User names: ${json.name}" } response.failure = { resp, json -> println "Request failed with status: ${resp.statusLine}" } }


上一篇:
下一篇:
切换中文