HttpClient Post Form data and get Response String

DefaultHttpClient httpclient = new DefaultHttpClient(); 
HttpPost httpost = new HttpPost("http://xxx/yyy/login"); 

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("key1", "value1"));  
params.add(new BasicNameValuePair("key2", "value2"));  
		
try {
	httpost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
	HttpResponse response = httpclient.execute(httpost);
	int status = response.getStatusLine().getStatusCode();
	String body = EntityUtils.toString(response.getEntity()); 
} catch (Exception e) {
	e.printStackTrace();
}  

 

posted @ 2016-08-23 10:59  webglcn  阅读(286)  评论(0编辑  收藏  举报