Json Send/Post error in blackberry

…衆ロ難τιáo~ 提交于 2019-12-12 02:55:07

问题


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);


回答1:


The value of method is a String to specify the request method HttpConnection.GET or HttpConnection.POST.

You have to specify it like:

c.setRequestProperty("method", HttpConnection.GET);

or

c.setRequestProperty("method", HttpConnection.POST);

You can use c.setRequestMethod() instead.

See more here



来源:https://stackoverflow.com/questions/10380400/json-send-post-error-in-blackberry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!