//需要说明的是,android的高版本中,http之类的请求必须要放在一个线程里面,否则程序报错退出。
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(
"http://xxxxxxx.aspx");
postParameters.add(new BasicNameValuePair("cityid", "广州市"));
//下面这一行是对字符进行urlEncode,会把中文转换成%xx%xx%xx这样的形式。
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity( postParameters,HTTP.UTF_8);
//一定要加上下面这一条,设置http请求头才行。
request.setEntity(formEntity);
HttpResponse response = client.execute(request);
if(response.getStatusLine().getStatusCode()==200)
{
String strResult = EntityUtils.toString(response.getEntity());
Log.e("haha",strResult);
}
} catch(Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}