Reputation: 71
I am trying to send a POST request using grails. I have read various post already present but no success. I have done following stuff till now.
Made below changes in my grails controller.
def index(){
withHttp(uri: "http://127.0.0.1:3001") {
def html = post(query : [q:'Groovy'])
assert html.HEAD.size() == 1
assert html.BODY.size() == 1
}}
when I am trying to access the controller it breaks.
Am I doing anything wrong here. I am sending JSON data in POST request which would later be saved? Any pointers directions would be very helpful.
Upvotes: 1
Views: 7313
Reputation: 2325
I have not tried doing this in a Grails controller but I figure since its groovy, it should work.
import groovyx.net.http.*
def http = new HTTPBuilder( 'http://127.0.0.1:3001' )
http.request( POST, JSON ) { req ->
body = [q:'groovy']
response.success = { resp, json ->
// handle repsonse
}
}
See more at: http://groovy.codehaus.org/modules/http-builder/doc/json.html and Groovy HTTPBuilder POST: missing method(s)
Upvotes: 1