2011-08-02 117 views

回答

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

+0

謝謝。但是,它的工作原理基於HTTP?或HTTPS?你能告訴我嗎? – Santhosh

+0

它適用於我的HTTP,沒有嘗試與https.But是非常簡單的東西:)。如果它可以幫助你不要忘記接受我的答案,從左側檢查它。謝謝:) – adrian

+0

我怎樣才能更改上面的代碼以使用HTTPS?你能告訴我嗎? – Santhosh

相關問題