HttpClient的使用----传递复杂参数
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(s2, "UTF-8");
httpPost.setEntity(entity);
httpPost.setHeader("Content-Type", "application/json;charset=utf8");
CloseableHttpResponse response = null;
String result = "";
try {
response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
result = EntityUtils.toString(responseEntity);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}