|
@@ -3,6 +3,7 @@ package com.steerinfo.dil.util;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.ParseException;
|
|
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.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.entity.StringEntity;
|
|
import org.apache.http.entity.StringEntity;
|
|
@@ -33,9 +34,13 @@ public class HTTPRequestUtils {
|
|
|
|
|
|
//创建httpclient对象
|
|
//创建httpclient对象
|
|
CloseableHttpClient client = HttpClients.createDefault();
|
|
CloseableHttpClient client = HttpClients.createDefault();
|
|
|
|
+
|
|
//创建post方式请求对象
|
|
//创建post方式请求对象
|
|
HttpPost httpPost = new HttpPost(url);
|
|
HttpPost httpPost = new HttpPost(url);
|
|
-
|
|
|
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom()
|
|
|
|
+ .setConnectTimeout(5000).setConnectionRequestTimeout(1000)
|
|
|
|
+ .setSocketTimeout(5000).build();
|
|
|
|
+ httpPost.setConfig(requestConfig);
|
|
//装填参数
|
|
//装填参数
|
|
StringEntity s = new StringEntity(json.toString(), "utf-8");
|
|
StringEntity s = new StringEntity(json.toString(), "utf-8");
|
|
s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
|
|
s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
|
|
@@ -44,7 +49,6 @@ public class HTTPRequestUtils {
|
|
System.out.println("请求地址:" + url);
|
|
System.out.println("请求地址:" + url);
|
|
System.out.println(json);
|
|
System.out.println(json);
|
|
// System.out.println("请求参数:"+nvps.toString());
|
|
// System.out.println("请求参数:"+nvps.toString());
|
|
-
|
|
|
|
//设置header信息
|
|
//设置header信息
|
|
//指定报文头【Content-type】、【User-Agent】
|
|
//指定报文头【Content-type】、【User-Agent】
|
|
// httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
|
|
// httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
|