我正在尝试做一个可以通过JSONObject
POST请求发送HttpConnection
的黑莓应用程序。 JSONObject是
{
"Contrasena" : "hy1tSPQc3K4IlSZLvd7U7g==",
"Plataforma" : "A",
"Usuario" : "user2323"
}
任何人都知道怎么做?
答案 0 :(得分:3)
您可以使用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();