I want to send JSON request through HTTPConnection but i am getting error when i am trying to get the response code.
Here is my code…
public void sendrequest(String url)throws IOException, JSONException
{
JSONObject postObject = new JSONObject();
postObject.put("method", method);
postObject.put("params", Parameters);
HttpConnection c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
c.setRequestProperty("Content-Length", "" + (postObject.toString().length() - 2));
c.setRequestProperty("method", method);
c.setRequestProperty("params", Parameters);
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK){
throw new IOException("HTTP response code: " + rc);
}
}
i get this code from Send JSON request from blackberry used in postObject.put(“method”, method);
The value of
methodis aStringto specify the request methodHttpConnection.GETorHttpConnection.POST.You have to specify it like:
or
You can use c.setRequestMethod() instead.
See more here