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

}

猜你喜欢

转载自blog.51cto.com/14137088/2331713