Http GET和Http Post傳送方式
阿新 • • 發佈:2018-12-31
POST方式
傳入List<NameValuePair> params,CloseableHttpClienthttpClient
if(httpClient==null)httpClient=HttpClients.createDefault();
HttpPosthttpPost=new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
if(Headers!=null) httpPost.setHeaders(Headers);
CloseableHttpResponse response
GET方式
if (params!= null&& !params.isEmpty()){
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(params, "UTF-8"));
}
System.out.println("---------url---------"+url);
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response