Last post Feb 15, 2010 10:30 AM by gggdei
Oct 15, 2008 08:06 AM|nraykar|LINK
This is my 1st post on this Forum. I am trying to build an application in C#.net 2005 which can read HTML
I am getting WebException in the code given in MSDN under Article
A WebException has been caught.
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 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) 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 Forms_HelpOnWebRequest.Page_Load(Object
sender, EventArgs e)
Code given Below
public class WebRequestGetExample
public static void Main ()
// Create a request for the URL.
WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
// Display the status.
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
// Cleanup the streams and the response.
Can anybody help me to solve this error ?
Oct 15, 2008 01:05 PM|nraykar|LINK
Oct 15, 2008 01:51 PM|Mr^B|LINK
Do you connect to the internet through a proxy/ISA server? If so you'll need to specify that in the code too:
Oct 16, 2008 07:15 AM|nraykar|LINK
Oct 16, 2008 07:21 AM|Murtaza_t|LINK
The error is more related to the firewall blocking the ports I suppose rather than your code.. make sure that there is no firewall between the servers and if there is any, they allow all the necessary ports through them.
Oct 16, 2008 07:51 AM|nraykar|LINK
Hi, Thanks for your reply.
Do we have to set the firewall setting OFF or ON
When we put the URL in Browser it Opens....But using code it is not getting any response from server, why this happens?
Oct 16, 2008 09:08 AM|Mr^B|LINK
No I donot use proxy....Proxy setting is Automatic/Default
Are you sure?
Most people don't even realise they are going through a proxy because it's automatically detected by most browsers (firefox/IE, etc)
If you can browse to it via a browser, but the code can't, then that usually points to a proxy configuration problem.
Feb 15, 2010 10:30 AM|gggdei|LINK
Hello, I was using Internet connection sharing in my wireless card properties because I had another computer connected through mine. I disabled it and it worked.