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) {
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章