3

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

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

有谁知道怎么做?

4

1 回答 1

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();
于 2012-07-29T02:20:59.003 回答