如何使用Https Post请求将JsonObject发送到服务器

时间:2011-08-02 14:13:46

标签: android

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

1 个答案:

答案 0 :(得分: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

相关问题