HttpClient——POST请求方法

CloseableHttpClient httpClient = HttpClients.createDefault();  

//如果发送是POST请求,创建HttpPost对象
HttpPost httppost = new HttpPost("http://localhost:8080/login");  

//post请求参数配置
List<NameValuePair> formparams = new ArrayList<NameValuePair>(); 
formparams.add(new BasicNameValuePair("name", "xxx")); formparams.add(new BasicNameValuePair("pwd", "123456")); UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); //设置编码格式为utf-8 httppost.setEntity(uefEntity); //设置POST请求参数 //使用httpclient的execute方法发送接口请求 CloseableHttpResponse response = httpClient.execute(httppost);

 

posted on 2016-04-28 14:04  TestJ  阅读(1460)  评论(0编辑  收藏  举报