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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
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)

Developer
Posts: 19,636
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. 

Highlighted
Developer
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!!

 

 

Developer
Posts: 19,636
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.