如何用Java httpcomponents实现HTTP GET和POST请求示例代码?
- 内容介绍
- 文章标签
- 相关推荐
本文共计191个文字,预计阅读时间需要1分钟。
引入的包为:+!–https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient–dependency+groupId:org.apache.httpcomponents+artifactId:httpclient+version:4.5.8+–dependency+实现的工具类为:im
引入的包为:
<!-- mvnrepository.com/artifact/org.apache.jiashubing.cn/tencenttest"; //需要传入的参数 Map<String, String> map = new HashMap<>(); map.put("code", "js"); map.put("day", "0"); map.put("city", "北京"); map.put("dfc", "1"); map.put("charset", "utf-8"); sendPost(url, map); String urlParam = "jiashubing.cn/talk/document?fileid=1234ji贾树丙"; sendGet(urlParam); } }
如果POST请求想要发送Json 格式的数据,只需要修改成这样:
String json = JSON.toJSONString(paramMap);
StringEntity requestEntity = new StringEntity(json, "utf-8");
httpPost.setEntity(requestEntity);
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。
本文共计191个文字,预计阅读时间需要1分钟。
引入的包为:+!–https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient–dependency+groupId:org.apache.httpcomponents+artifactId:httpclient+version:4.5.8+–dependency+实现的工具类为:im
引入的包为:
<!-- mvnrepository.com/artifact/org.apache.jiashubing.cn/tencenttest"; //需要传入的参数 Map<String, String> map = new HashMap<>(); map.put("code", "js"); map.put("day", "0"); map.put("city", "北京"); map.put("dfc", "1"); map.put("charset", "utf-8"); sendPost(url, map); String urlParam = "jiashubing.cn/talk/document?fileid=1234ji贾树丙"; sendGet(urlParam); } }
如果POST请求想要发送Json 格式的数据,只需要修改成这样:
String json = JSON.toJSONString(paramMap);
StringEntity requestEntity = new StringEntity(json, "utf-8");
httpPost.setEntity(requestEntity);
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

