将写代码过程中常用的一些代码收藏起来,下面的资料是关于 Android通过HttpClient执行Http Post请求的代码,应该对小伙伴们也有用处。
public void postData() {
HttpClient httpclient = new DefaultHttpClient();
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(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) {
}
}