【问题标题】:How can i send JsonObject to server using Https Post request如何使用 Https Post 请求将 JsonObject 发送到服务器
【发布时间】:2011-10-18 07:33:42
【问题描述】:

如何使用 HTTPS Post 请求将 JSON 格式的 Android 应用程序数据(mobileNumber 和消息)发送到服务器。请帮我。

【问题讨论】:

    标签: android


    【解决方案1】:
    HttpClient httpclient =new DefaultHttpClient();
    
    HttpPost  httppost=new HttpPost(name of the website);
    try{
    
        JSONObject j = new JSONObject();
        j.put("engineer", "me");
    
        httppost.setEntity(new UrlEncodedFormEntity(j));    
        HttpResponse response = httpclient.execute(httppost);
    
        /*Checking response*/
        if(response!=null)
        {   
            responseBody = EntityUtils.toString(response.getEntity());
    
        }
        if(responseBody.equals("ok"))
        {
    
            //...do something
    
        }
    } catch(ClientProtocolException e) {
    
    } catch (IOException e) {
        // TODO Auto-generated catch block
    } catch(Exception e){
        e.printStackTrace();
    }
    

    您也可以在这里查看:Android JSON HttpClient to send data to PHP server with HttpResponse

    【讨论】:

    • 谢谢。但是,它基于 HTTP 工作?还是HTTPS??你能告诉我吗?
    • 它适用于 Http 对我来说,还没有尝试使用 https。但它非常简单:)。如果它帮助你不要忘记通过从左侧检查来接受我的答案。谢谢:)
    • 如何更改上述代码以在 HTTPS 上工作?你能告诉我吗?
    • 抱歉回复晚了,但似乎这对 http 和 https 都有效!你试过了吗?它不起作用?
    • 我没试过。但我想知道它是否也适用于“Https”?你能澄清一下吗?
    猜你喜欢
    • 2012-12-12
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    相关资源
    最近更新 更多