packagecom.tradeyun;importjava.io.IOException;importjava.io.UnsupportedEncodingException;importjava.net.URI;importjava.net.URISyntaxException;importjava.util.ArrayList;importjava.util.List;importorg.apache.http.HttpEntity;importorg.apache.http.HttpResponse;importorg.apache.http.NameValuePair;importorg.apache.http.client.ClientProtocolException;importorg.apache.http.client.HttpClient;importorg.apache.http.client.config.RequestConfig;importorg.apache.http.client.entity.UrlEncodedFormEntity;importorg.apache.http.client.methods.CloseableHttpResponse;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.client.methods.HttpPost;importorg.apache.http.client.utils.URIUtils;importorg.apache.http.client.utils.URLEncodedUtils;importorg.apache.http.impl.client.CloseableHttpClient;importorg.apache.http.impl.client.DefaultHttpClient;importorg.apache.http.impl.client.HttpClientBuilder;importorg.apache.http.impl.client.HttpClients;importorg.apache.http.impl.conn.PoolingClientConnectionManager;importorg.apache.http.message.BasicNameValuePair;importorg.apache.http.util.EntityUtils;/***@authorQiaoJiafei
*@version创建时间:2015年12月18日 上午10:03:12
* 类说明*/
public classTestHttpClientParameter {public static voidmain(String args[]) {/*HttpClient httpclient = new DefaultHttpClient(new PoolingClientConnectionManager());
String s = "";
HttpResponse response = null;
HttpEntity entity = null;
String url = "http://172.16.30.244:8090/gm_product_site/assignmentApply/auth";
System.out.println("url=========="+url);
HttpPost post = new HttpPost(url);
List formparams = new ArrayList();
formparams.add(new BasicNameValuePair("applyId","1"));
formparams.add(new BasicNameValuePair("isPass","true"));
//formparams.add(new BasicNameValuePair("pwd","aaaaaa1"));
//formparams.add(new BasicNameValuePair("pwd", "aaaaaa1"));
UrlEncodedFormEntity uefEntity;
try {
uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
post.setEntity(uefEntity);
System.out.println("executing request " + post.getURI());
response = httpclient.execute(post);
entity = response.getEntity();
s= EntityUtils.toString(entity, "UTF-8");
System.out.println(s);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/ //不成功TestHttpClientParameter t= newTestHttpClientParameter();
t.post3();
}public voidpost3() {
HttpClient httpclient= new DefaultHttpClient(newPoolingClientConnectionManager());
String s= "";
HttpResponse response= null;
HttpEntity entity= null;
String url= "http://172.16.30.244:8090/gm_product_site/assignmentApply/auth";
System.out.println("url=========="+url);
HttpPost post= null;
List formparams= newArrayList();
formparams.add(new BasicNameValuePair("applyId","1"));
formparams.add(new BasicNameValuePair("isPass","true"));
UrlEncodedFormEntity uefEntity;try{
uefEntity= new UrlEncodedFormEntity(formparams, "UTF-8");
URI uri=null;try{
uri= URIUtils.createURI("http", "172.16.30.244:8090", -1, "/gm_product_site/assignmentApply/auth",
URLEncodedUtils.format(formparams,"UTF-8"), null);
}catch(URISyntaxException e) {//TODO Auto-generated catch block
e.printStackTrace();
}
post= newHttpPost(uri);
System.out.println(post.getURI());
response=httpclient.execute(post);
entity=response.getEntity();
s= EntityUtils.toString(entity, "UTF-8");
System.out.println(s);
}catch(Exception e) {//TODO Auto-generated catch block
e.printStackTrace();
}
}
}