|
|
@ -184,12 +184,13 @@ public class HttpClientUtils { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* desc: 发送get请求 |
|
|
|
* param:url, params |
|
|
|
* return: CallResult<String> |
|
|
|
* date: 2019/2/21 9:16 |
|
|
|
* 发送get请求 |
|
|
|
* |
|
|
|
* @author: jianjun liu |
|
|
|
* @param url |
|
|
|
* @param params |
|
|
|
* @return com.elink.esua.httpclient.ResultDto |
|
|
|
* @author zhy |
|
|
|
* @date 2022/9/6 9:41 |
|
|
|
*/ |
|
|
|
public ResultDto sendGet(String url, Map<String, Object> params) { |
|
|
|
|
|
|
@ -202,23 +203,31 @@ public class HttpClientUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
HttpGet httpGet = new HttpGet(builder.build()); |
|
|
|
httpGet.setConfig(requestConfig); |
|
|
|
httpGet.setConfig(REQUEST_CONFIG); |
|
|
|
return getResult(client.execute(httpGet)); |
|
|
|
} catch (Exception e) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* post json |
|
|
|
* |
|
|
|
* @param url |
|
|
|
* @param jsonStrParam |
|
|
|
* @param headerMap |
|
|
|
* @return com.elink.esua.httpclient.ResultDto |
|
|
|
* @author zhy |
|
|
|
* @date 2022/9/6 9:41 |
|
|
|
*/ |
|
|
|
public ResultDto sendPostByJSONAndHeader(String url, String jsonStrParam,Map<String,String> headerMap) { |
|
|
|
|
|
|
|
try { |
|
|
|
HttpPost httppost = new HttpPost(url); |
|
|
|
httppost.setConfig(requestConfig); |
|
|
|
httppost.setConfig(REQUEST_CONFIG); |
|
|
|
httppost.addHeader(HEADER_CONTENT_TYPE, HEADER_APPLICATION_JSON); |
|
|
|
if (null != headerMap){ |
|
|
|
headerMap.forEach((k,v) -> { |
|
|
|
httppost.addHeader(k,v); |
|
|
|
}); |
|
|
|
headerMap.forEach(httppost::addHeader); |
|
|
|
} |
|
|
|
if (!StringUtils.isEmpty(jsonStrParam)) { |
|
|
|
StringEntity se = new StringEntity(jsonStrParam, UTF8); |
|
|
@ -231,17 +240,25 @@ public class HttpClientUtils { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* post form |
|
|
|
* |
|
|
|
* @param url |
|
|
|
* @param paramsMap |
|
|
|
* @param headerMap |
|
|
|
* @return com.elink.esua.httpclient.ResultDto |
|
|
|
* @author zhy |
|
|
|
* @date 2022/9/6 9:42 |
|
|
|
*/ |
|
|
|
public ResultDto sendPostAndHeader(String url, Map<String, Object> paramsMap, Map<String,String> headerMap) { |
|
|
|
|
|
|
|
try { |
|
|
|
HttpPost httppost = new HttpPost(url); |
|
|
|
httppost.setConfig(requestConfig); |
|
|
|
httppost.setConfig(REQUEST_CONFIG); |
|
|
|
|
|
|
|
httppost.addHeader(HEADER_CONTENT_TYPE, HEADER_APPLICATION_FORM_URL_ENCODED); |
|
|
|
if (null != headerMap){ |
|
|
|
headerMap.forEach((k,v) -> { |
|
|
|
httppost.addHeader(k,v); |
|
|
|
}); |
|
|
|
headerMap.forEach(httppost::addHeader); |
|
|
|
} |
|
|
|
List<NameValuePair> list = new ArrayList<NameValuePair>(); |
|
|
|
for (String key : paramsMap.keySet()) { |
|
|
@ -258,7 +275,7 @@ public class HttpClientUtils { |
|
|
|
} |
|
|
|
|
|
|
|
/*** 超时设置 ****/ |
|
|
|
private static RequestConfig requestConfig = RequestConfig.custom() |
|
|
|
private static final RequestConfig REQUEST_CONFIG = RequestConfig.custom() |
|
|
|
.setSocketTimeout(soTimeout) |
|
|
|
.setConnectTimeout(connectionTimeout) |
|
|
|
.setConnectionRequestTimeout(soTimeout) |
|
|
|