1. 程式人生 > >Android下通過HttpClient執行 HTTP POST 請求 的程式碼

Android下通過HttpClient執行 HTTP POST 請求 的程式碼

如下程式碼段是關於Android下通過HttpClient執行 HTTP POST 請求 的程式碼。
public void postData() {
HttpClient httpclient = new DefaultHttpClient();

try {
    List<NameValuePair> nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
    nameValuePairs.add(new BasicNameValuePair("id", "12345"));
    nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
} catch (IOException e) {
}

}