HttpClient4.3.6版本以上的http和https请求写法
Posted lljliulljn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HttpClient4.3.6版本以上的http和https请求写法相关的知识,希望对你有一定的参考价值。
import
java.io.IOException;
import
java.io.UnsupportedEncodingException;
import
java.security.cert.CertificateException;
import
java.security.cert.X509Certificate;
import
java.util.ArrayList;
import
java.util.Iterator;
import
java.util.List;
import
java.util.Map;
import
javax.net.ssl.SSLContext;
import
javax.servlet.http.HttpServletRequest;
import
org.apache.http.Consts;
import
org.apache.http.HttpEntity;
import
org.apache.http.NameValuePair;
import
org.apache.http.ParseException;
import
org.apache.http.client.config.RequestConfig;
import
org.apache.http.client.entity.UrlEncodedFormEntity;
import
org.apache.http.client.methods.CloseableHttpResponse;
import
org.apache.http.client.methods.HttpGet;
import
org.apache.http.client.methods.HttpPost;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import
org.apache.http.conn.ssl.SSLContextBuilder;
import
org.apache.http.conn.ssl.TrustStrategy;
import
org.apache.http.entity.StringEntity;
import
org.apache.http.impl.client.CloseableHttpClient;
import
org.apache.http.impl.client.HttpClients;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import
org.apache.http.message.BasicHeader;
import
org.apache.http.message.BasicNameValuePair;
import
org.apache.http.util.EntityUtils;
import
org.slf4j.Logger;
import
org.slf4j.LoggerFactory;
import
com.jfinal.kit.StrKit;
public
class
HttpUtil
private
static
final
Logger logger = LoggerFactory.getLogger(HttpUtil.
class
);
// 连接超时时间
private
static
final
int
CONNECTION_TIMEOUT =
3000
;
//3秒
// 读数据超时时间
private
static
final
int
READ_DATA_TIMEOUT =
6000
;
//6秒
private
static
PoolingHttpClientConnectionManager connManager =
为啥 PoolingHttpClientConnectionManager 提供越来越慢的连接?
使用HttpClient 发送 GETPOST(FormDataRaw)PUTDelete请求及文件上传
Spring Cloud Gateway——2020.x以上版本HTTP 503 或 NoLoadBalancer[负载均衡]解决方案
Spring Cloud Gateway——2020.x以上版本HTTP 503 或 NoLoadBalancer[负载均衡]解决方案