java调用第三方的http post接口:
可调用接口的工具类如下:
public class HttpClientUtils{
public static String sendPost(String params,String url){
String content="";
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(300 * 1000)
.setConnectTimeout(300 * 1000)
.build();
HttpPost post = new HttpPost(url);
post.setConfig(requestConfig);
post.setHeader("Content-Type","application/json;charset=utf-8");
StringEntity postingString = new StringEntity(params,
"utf-8");
post.setEntity(postingString);
CloseableHttpResponse response = httpClient.execute(post);
content = EntityUtils.toString(response.getEntity());
System.out.println(content);
} catch (SocketTimeoutException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return content;
}}