我正在尝试做一个可以通过JSONObject POST请求发送HttpConnection的黑莓应用程序。 JSON对象是

{
   "Contrasena" : "hy1tSPQc3K4IlSZLvd7U7g==",
   "Plataforma" : "A",
   "Usuario" : "user2323"
}

有人知道吗?

最佳答案

您可以为此使用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();

10-07 19:30