aspose file tools*
The moose likes Web Services and the fly likes How do I send a JSON object from the client to the server in a POST request? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How do I send a JSON object from the client to the server in a POST request?" Watch "How do I send a JSON object from the client to the server in a POST request?" New topic
Author

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

james frain
Ranch Hand

Joined: Apr 06, 2011
Posts: 36
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

Joined: Mar 22, 2000
Posts: 12835
    
    5
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

Joined: Apr 06, 2011
Posts: 36
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

Joined: Mar 07, 2010
Posts: 8
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

Joined: Apr 06, 2011
Posts: 36
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I send a JSON object from the client to the server in a POST request?