使用带有BlackBerry的HttpConnection POST发送JSONObject

时间:2012-07-29 01:07:48

标签: json post blackberry httpconnection

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

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

任何人都知道怎么做?

1 个答案:

答案 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();