出现这个问题,一直很恼火!!! 主要是之前一直采用http发送请求没有问题,修改成https就有问题了!!! 于是就考虑到,https协议问题???
解决办法
//添加https兼容处理
HttpWebRequest request = null;
if (serviceAddress.StartsWith("https", StringComparison.OrdinalIgnoreCase))
{
// 这里设置了协议类型。把SSL验证的设置写到HttpRequect创建之前
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.CheckCertificateRevocationList = true;
ServicePointManager.DefaultConnectionLimit = 100;
ServicePointManager.Expect100Continue = true;
request = WebRequest.Create(serviceAddress) as HttpWebRequest;
request.ProtocolVersion = HttpVersion.Version11;
request.KeepAlive = false;
}
else
{
request = (HttpWebRequest)WebRequest.Create(serviceAddress);
}
重点:
- 添加https协议设置
- 把SSL验证的设置写到HttpRequect创建之前
详细请查阅如下: https://blog.csdn.net/qq_16771097/article/details/120786063
|