<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.1.12</version>
</dependency>
/**
* Json格式post请求接口调用
* @param url 接口地址
* @param jsonStr Json格式请求参数体
* @return
*/
public static String postJson(String url, JSONObject jsonStr){
String retJson = "";
try {
retJson = HttpRequest.post(url).header("Content-Type","application/json")
.timeout(10000).body(jsonStr.toJSONString()).execute().body();
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
return retJson;
}