views:

66

answers:

1

I'm using .Net Web Request to read the html of selected Webpages.

Once in a while I'm getting the following error:

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)

I know for sure that the target URL is available.

Any idea what is the cause of the error?

A: 

There could be different reasons for this happening. Maybe the target server is throttling the response because it believes the request comes from a bot. In this case you might consider sending proper HTTP headers (if it works in your browser, try sending the same request headers). Also there could be a proxy in between that you need to configure and use.

Darin Dimitrov
Thx for the answer . I'm using the following UserAgent "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1". the error happens only once in a while so i dont really think its the UA. Regarding the proxy what configuration do you mean?
sharru
Do you need to use a proxy server to access the URL?
Darin Dimitrov
Yes im using a proxy.
sharru
And have you configured the `WebRequest` to use this proxy?
Darin Dimitrov
Yes i did. "webRequest.Proxy = new WebProxy(address)" , and as i said most of the web-requests i make work perfectly. its just a few that get the above error.
sharru
Well then it seems that the problem is related to the server.
Darin Dimitrov
You should get a wireshark trace, and see what is happening? Did the connection succeed at first,then get torndown by the server? Wireshark trace will show.
feroze