android http协议post请求方式

HttpPost(import org.apache.http.client.methods.HttpPost )

//POST 请求
void UpdateInfo() {
String destUrl="http://www.topsznn.com:7077/Ajax/GetWeather.ashx";
HttpPost httpRequest =new HttpPost(destUrl);
List <NameValuePair> params=new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("scity",cityName));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest);
if(httpResponse.getStatusLine().getStatusCode()==200){
String strResult=EntityUtils.toString(httpResponse.getEntity());
sb.append(strResult);
System.out.println(strResult);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
}

你可能感兴趣的:(android http协议post请求方式)