Just a snippet of how to do GET/POST request in Groovy Grails.
try{
HttpBuilder http = new HTTPBuilder('your URL here')
def postBody = [name: 'bob', title: 'construction worker']
http.post(body: postBody,
requestContentType: ContentType.JSON) { resp, json ->
//This is to assume everything is successful within this //closure
println "response status " + resp.statusLine
println "json response " + json
}
}catch(HttpResponseException ex){
//handle your errors here
}
try{
HttpBuilder http = new HTTPBuilder('your URL here')
def postBody = [name: 'bob', title: 'construction worker']
http.post(body: postBody,
requestContentType: ContentType.JSON) { resp, json ->
//This is to assume everything is successful within this //closure
println "response status " + resp.statusLine
println "json response " + json
}
}catch(HttpResponseException ex){
//handle your errors here
}
Comments
Post a Comment