02-24-2011 03:02 AM
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)
02-24-2011 04:41 AM
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.
02-24-2011 07:45 AM
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!!
02-24-2011 08:52 AM
Somehting like:
http.setRequestProperty(HttpProtocolConstants.HEAD
Your Server technical people shoud guide you on this.