|
@@ -3,6 +3,7 @@ package com.steerinfo.dil.util;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.ParseException;
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
@@ -41,6 +42,10 @@ public class HTTPRequestUtils {
|
|
|
s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
|
|
|
|
|
|
httpPost.setEntity(s);
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom()
|
|
|
+ .setConnectTimeout(10 * 1000)
|
|
|
+ .setSocketTimeout(10 * 1000)
|
|
|
+ .build();
|
|
|
|
|
|
System.out.println("请求地址:" + url);
|
|
|
System.out.println(json);
|
|
@@ -51,6 +56,7 @@ public class HTTPRequestUtils {
|
|
|
|
|
|
httpPost.setHeader("Content-type", "application/json");
|
|
|
httpPost.setHeader("-UserAgent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
|
|
+ httpPost.setConfig(requestConfig);
|
|
|
|
|
|
|
|
|
CloseableHttpResponse response = client.execute(httpPost);
|
|
@@ -136,6 +142,10 @@ public class HTTPRequestUtils {
|
|
|
CloseableHttpClient client = HttpClients.createDefault();
|
|
|
|
|
|
HttpGet httpGet = new HttpGet(url);
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom()
|
|
|
+ .setConnectTimeout(10 * 1000)
|
|
|
+ .setSocketTimeout(10 * 1000)
|
|
|
+ .build();
|
|
|
|
|
|
|
|
|
|
|
@@ -149,6 +159,7 @@ public class HTTPRequestUtils {
|
|
|
|
|
|
httpGet.setHeader("Content-type", "application/json");
|
|
|
httpGet.setHeader("-UserAgent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
|
|
+ httpGet.setConfig(requestConfig);
|
|
|
|
|
|
|
|
|
CloseableHttpResponse response = client.execute(httpGet);
|