Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Kiran_Snist
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

how to send JSON Object over HTTP???

Hi all!!

 

I have a JSON object , which i have changed it into a String. Now i want to send that String over HTTP using POST method, because at the server side they can only accept JSON String as a response, so i need to only send JSON String, not other than that like BYTE array or something else

 

 

So, i want ur Help!!

 

 

 

regards

Kiran

(Snist)

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to send JSON Object over HTTP???

The HttpConnection JavaDoc has an example of doing a POST.  There are other examples on the forum too.  Search for POST.  The mechanism is not specific to JSON strings, though you might want to set an encoding method to indicate you are sending json, rather than URL Encoded data which is what most samples will send. 

Please use plain text.
Developer
Kiran_Snist
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: how to send JSON Object over HTTP???

Hi peter_stranger

 

I wrote dis code:

 

reply=a.getSuppliers();
http.setRequestProperty("entity", reply);
http.setRequestMethod(HttpConnection.POST);
OutputStream httpOutput=http.openOutputStream();
byte data[]=reply.getBytes("UTF-8");
http.setRequestProperty("Content-Length", Integer.toString(data.length));
httpOutput.write(data);
httpOutput.flush();
httpOutput.close();

 

As in dis code, if i amsending that byte array.. I am getting HTTP ERROR 415... since the server side code only accepting JSON String (somthing called JAXELEMENT).. So, how could i Encode an encodeing method for JSON String??

 

Plz guide me... Urgent!!

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to send JSON Object over HTTP???

Somehting like:

 

http.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE,"application / requestJson");

 

Your Server technical people shoud guide you on this. 

Please use plain text.