pom引入
<!-- Apache HttpClient fluent -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>4.5.8</version>
</dependency>
code
Request request = Request.Post(url);
request.addHeader("xx", "xxx");
String result = null;
try {
result = request.useExpectContinue()
.version(HttpVersion.HTTP_1_1)
.bodyString(JSON.toJSONString(params), ContentType.APPLICATION_JSON)
.setHeader("Content-Type", "application/json; charset=UTF-8")
.execute()
.returnContent()
.asString();
System.out.println(result);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
参考文章:https://blog.csdn.net/asd0654123/article/details/90554405