Skip to content

Instantly share code, notes, and snippets.

@lyhcode
Forked from anonymous/HttpTest.groovy
Created July 31, 2013 08:26
Show Gist options
  • Save lyhcode/6120315 to your computer and use it in GitHub Desktop.
Save lyhcode/6120315 to your computer and use it in GitHub Desktop.
/**
* HttpBuilder Testing
*/
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.2' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'http://localhost:8080' )
http.request( PUT, JSON ) {
uri.path = '/test1/rest/testPut'
uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]
body = [ a:1, b:2, c:3 ]
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
response.success = { resp, json ->
println resp.statusLine
println json.result
}
response.failure = { resp ->
println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment