.Net Web请求 - 无法连接到远程服务器

时间:2010-09-07 12:55:21

标签: c# .net httpwebrequest

我正在使用.Net Web Request来阅读所选网页的html。

偶尔我会收到以下错误:

2010-09-05 13:14:51,986 [File_29] ERROR Boxer.Classes.GetLinks [(null)] - HtmlUtils - GetResponse - Url - http://domain.com/index.html
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 69.212.110.118:5068
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at Boxer.Classes.GetLinks.GetResponse(String url, Int32 timeout, Boolean& timeoutException)

我确信目标网址可用。

知道错误的原因是什么?

1 个答案:

答案 0 :(得分:1)

这种情况可能有不同的原因。也许目标服务器会限制响应,因为它认为请求来自机器人。在这种情况下,您可以考虑发送正确的HTTP标头(如果它在浏览器中有效,请尝试发送相同的请求标头)。此外,您可能需要配置和使用代理。