我想通过 HTTPConnection 发送 JSON 请求,但是当我尝试获取响应代码时出现错误。这是我的代码...
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);
}
}
我从postObject.put("method", method); 中使用的黑莓发送 JSON 请求中获取此代码;