Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I send a JSON object from the client to the server in a POST request?

 
james frain
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have my app working where my Client can request a JSON object from the server and parses it fine.
Now , I want to build a JSON object on the client side so how do I send this to the server?
I have a HttpClient, A HttpPost and a JSON object, but could any show me how to "stuff" the JSON object into the POST request's body ( If that's the word ) ?

Thanks ... J
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just write the JSON text into the body of the POST request.

This example is XML but any text can be written this way.

Bill
 
james frain
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.
Still having problems on client side though.
Here is my code so far

Problem is the first call hits my POST handler on the server side but when I try to add an entity the call never reaches the server side. No exceptions thrown on client side. Is adding an entity to the HttpPost the correct way to do this?
 
Kevin Reynolds
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello James,

I am facing a related issue and I am wondering if you found the solution to your problem?

My problem is more related to finding and invoking the correct MessageBodyReader and I believe the problem is on my server side, but I am not 100% certain. Your message title perfectly describes the client-side of what I am doing.

My posting: http://www.coderanch.com/t/564856/Portals-Portlets/java/Tomcat-Jersey-JSON-Oh



 
james frain
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Kevin,
We got around the initial problem. It was to do with the method signatures on the server side. We had a @POST handler which we couldn't figure out why it was not being called but the problem was our method signature didn't take a "Representation" object !!
Anyways we have ditiched out REST solution for the time being and going with an RPC solution first. Very easy to implement in comparison but we defo indend to plug in a REST solution later on this year when we get some proof of concepts ironed out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic