• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: https://coderanch.com/t/564856/Portals-Portlets/java/Tomcat-Jersey-JSON-Oh



 
james frain
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic