发送post请求携带requestParams参数

public static String sendHttpPost(String url, String JSONBody) throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader(“Content-Type”, “application/x-www-form-urlencoded”);
httpPost.setEntity(new StringEntity(JSONBody));
CloseableHttpResponse response = httpClient.execute(httpPost);
// System.out.println(response.getStatusLine().getStatusCode() + “\n”);
HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, “UTF-8”);
// System.out.println(responseContent);
response.close();
httpClient.close();
return responseContent;
}

你可能感兴趣的:(java)