绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
C#后端代码抓取页面偶发性与主机连接失败
2019-11-12 10:56:50

用 HttpWebResponse 抓取页面时链接主机失败,这种情况是偶然发生,网站自己用的按说并发性不会很高,有没有大侠知道什么原因嘛?

抓取代码:

HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);

HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();

StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8);

String str = sr.ReadToEnd();

String appPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase.TrimEnd(Path.DirectorySeparatorChar);

sr.Close();

英文原文报错 :

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

下面是翻译过来的:

System.Net.Sockets。SocketException:连接尝试失败,因为被连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机没有响应

分享好友

分享这个小栈给你的朋友们,一起进步吧。

IT知识联盟
创建时间:2019-07-05 15:30:45
分享收集到的大小知识点
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

栈主、嘉宾

查看更多
  • 王超
    栈主

小栈成员

查看更多
  • ?
  • youou
  • gamebus
  • chinacc
戳我,来吐槽~