请求部分代码:
if (!(url.Contains("http://") || url.Contains("https://")))
url = "http://" + url;
if (url.StartsWith("https", StringComparison.InvariantCultureIgnoreCase))
{
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = method.Trim().ToLower();
request.Timeout = timeout;
request.AllowAutoRedirect = true;
request.ContentType = EnumDescription.GetRemark(contenttype); //"text/html";
request.Accept = string.IsNullOrWhiteSpace(Accept) ? "text/html,application/xhtml+xml,*/*,zh-CN" : Accept;
request.UserAgent ="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
request.KeepAlive = true;
request.ServicePoint.Expect100Continue = false;
request.ProtocolVersion = HttpVersion.Version10;
异常情况:分页去请求其他接口可能前面几次是成功的,后面就出现这个错误,但也不是全部都会这样,感觉和数据量是不是有啥关系, 而且他会一直等一两分钟他才会报这个错误,我超时时间已经设置成60秒还是如此,这个和服务器,路由啥的有没有什么关系,因为原来没有过这个问题,近期才出现,我本地调试也都没这个问题
网上说直接用:ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
一直提示:The request was aborted: Could not create SSL/TLS secure channel.
错误异常:
Received an unexpected EOF or 0 bytes from the transport stream. at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.IO.StreamReader.ReadBuffer() at System.IO.StreamReader.ReadToEnd()
xp客户端?
Windows server2016
建议分别试试一下以下3个协议:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
https://forums.asp.net/t/2054166.aspx?Received+an+unexpected+EOF+or+0+bytes+from+the+transport+stream
.net framework版本是多少?
– dudu 6年前@dudu: .net framework 4.5
– pengjie186@qq.com 6年前