【问题标题】:Send JSONObject using HttpConnection POST with BlackBerry使用 HttpConnection POST 与 BlackBerry 发送 JSONObject
【发布时间】:2012-07-27 04:45:50
【问题描述】:
我正在尝试做一个可以通过HttpConnection POST 请求发送JSONObject 的黑莓应用程序。 JSONObject 是
{
"Contrasena" : "hy1tSPQc3K4IlSZLvd7U7g==",
"Plataforma" : "A",
"Usuario" : "user2323"
}
有人知道怎么做吗?
【问题讨论】:
标签:
json
post
blackberry
httpconnection
【解决方案1】:
您可以为此使用URLEncodedPostData 类。像这样使用
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("Content-Type", "application/json");
URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
encPostData.setData(JsonString);//set your jsonstring
byte[] postData = encPostData.toString().getBytes("UTF-8");
httpConn.setRequestProperty("Content-Length", String.valueOf(postData.length));
httpConn.openOutputStream().write(encPostData.getBytes());
int Response = httpConn.getResponseCode();