Http GET和Http Post发送方式

来源:互联网 发布:微赞是什么样的软件 编辑:程序博客网 时间:2024/05/17 05:58

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=httpClient.execute(httpPost);


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 =httpClient.execute(httpGet);


 


阅读全文
0 0
原创粉丝点击