在黑莓的Json发送/ POST错误 [英] Json Send/Post error in blackberry
问题描述
我想通过HttpConnection的发送JSON请求,但我得到的错误,当我试图得到响应code。
这里是我的code ...
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);
}
}
我得到这个code从<一个href=\"http://%22http://stackoverflow.com/questions/9339656/send-json-request-from-blackberry-application%22%20but%20never%20understood%20what%20is%20value%20of%20the%20variable\"
i get this code from Send JSON request from blackberry used in postObject.put("method", method);
推荐答案
的值法
是字符串
指定请求方法 HttpConnection.GET
或 HttpConnection.POST
。
The value of method
is a String
to specify the request method HttpConnection.GET
or HttpConnection.POST
.
您必须指定它喜欢:
c.setRequestProperty("method", HttpConnection.GET);
或
c.setRequestProperty("method", HttpConnection.POST);
您可以使用<一个href=\"http://www.blackberry.com/developers/docs/5.0.0api/javax/microedition/io/HttpConnection.html#setRequestMethod%28java.lang.String%29\"相对=nofollow> c.setRequestMethod()代替
查看更多<一个href=\"http://stackoverflow.com/questions/9339656/send-json-request-from-blackberry-application\">here
这篇关于在黑莓的Json发送/ POST错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!