首页 新闻 会员 周边 捐助

WebRequest 出现异常:Received an unexpected EOF or 0 bytes from the transport stream.

0
悬赏园豆:100 [待解决问题]

请求部分代码:

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()
pengjie186@qq.com的主页 pengjie186@qq.com | 初学一级 | 园豆:102
提问于:2018-02-24 10:24

.net framework版本是多少?

dudu 6年前

@dudu: .net framework 4.5

pengjie186@qq.com 6年前
< >
分享
所有回答(3)
0

xp客户端?

日暮青色 | 园豆:495 (菜鸟二级) | 2018-02-24 10:48

Windows server2016

支持(0) 反对(0) pengjie186@qq.com | 园豆:102 (初学一级) | 2018-02-24 10:57
0

建议分别试试一下以下3个协议:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
dudu | 园豆:30778 (高人七级) | 2018-02-24 11:18
0

https://forums.asp.net/t/2054166.aspx?Received+an+unexpected+EOF+or+0+bytes+from+the+transport+stream

Yu | 园豆:12990 (专家六级) | 2018-02-24 13:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册