httpclient-4.5.6.jar
httpcore-4.4.4.jar
需要添加两个jar包
post方法代码:
public String addPrimaryContract(JSONObject json) {
String result = "";
String path = "接口地址";
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(path);
//添加参数
HttpEntity entity = new StringEntity(json.toString(),ContentType.APPLICATION_JSON);
post.setEntity(entity);
try {
HttpResponse response = client.execute(post);
result = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}