【问题标题】: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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      相关资源
      最近更新 更多