http协议中post方法发出请求

网友投稿 554 2022-10-24

http协议中post方法发出请求

http协议中post方法发出请求

package com.chinaums.szm.test.base.igoodful;import com.fasterxml.jackson.databind.ObjectMapper;import org.apache.org.apache.org.apache.org.apache.org.apache.org.apache.org.apache.org.apache.org.apache.org.apache.org.junit.Test;import java.io.IOException;import java.util.*;public class TestPost { public String doPost(String url, Map map, String charset){ CloseableHttpClient = null; HttpPost = null; String result = null; try{ = HttpClients.createDefault(); =new HttpPost(url); List list = new ArrayList<>(); Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()){ Map.Entry entry =(Map.Entry) iterator.next(); list.add(new BasicNameValuePair(entry.getKey(),entry.getValue())); } if (list.size() > 0){ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,charset); } HttpResponse = if (!= null){ HttpEntity = if (!= null){ result = EntityUtils.toString( } } }catch (Exception ex){ ex.printStackTrace(); } return result; }@Test public void test() throws IOException { String url = " Map map = new HashMap<>(); map.put("page","100"); String result = this.doPost(url,map,"UTF-8");//将输出更加优美的方式展示出。 ObjectMapper mapper = new ObjectMapper(); Object object = mapper.readValue(result,Object.class);mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object)); }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Integer类之成员变量
下一篇:kafka手动调整分区副本数的操作步骤
相关文章

 发表评论

暂时没有评论,来抢沙发吧~