HTTPBuilder and post

Posting using HTTPBuilder to post I have only gotten to work using the request method.

HttpBuilder post docs

Here is a code snippet that I use to that works sending JSON to a server method that returns JSON.


def http = new HTTPBuilder("http://foo.com")

http.request(Method.POST){
  uri.path = "/do/something"
  send groovyx.net.http.ContentType.URLENC,
       [name: "admin", action: "save"] response.success = {resp, json ->
    println "status $resp.status"
    println "status info"
    resp.properties { name, value ->
      println "$name : $value"
    }
    println "json"
    json.properties { name, value ->
      println "$name : $value"
    }
 }
 response.failure = {resp, json ->
   println "status $resp.status"
   println "response info"
   resp.properties { name, value ->
     println "$name : $value"
   }
   println "json"
   json.properties { name, value ->
     println "$name : $value"
   }
 }
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s