HttpWebRequest fails

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I tried to send a HttpWebRequest, but it doesn't work, although it's so
simple.
Here is the Code:

HttpWebRequest InetReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com/");

HttpWebResponse myResponse;
try
{
myResponse = (HttpWebResponse)InetReq.GetResponse();
}
catch (Exception ex)
{
...
}

In the catch routine I get a MessageBox showing exception "Unable to connect
to the remote server" and inner exception "Connection could not be
established because the host refused the connection".
What's wrong here?

Thanks!
 
Markus Eder said:
I tried to send a HttpWebRequest, but it doesn't work, although it's so
simple.
Here is the Code:

HttpWebRequest InetReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com/");

HttpWebResponse myResponse;
try
{
myResponse = (HttpWebResponse)InetReq.GetResponse();
}
catch (Exception ex)
{
...
}

In the catch routine I get a MessageBox showing exception "Unable to connect
to the remote server" and inner exception "Connection could not be
established because the host refused the connection".
What's wrong here?

Are you able to make a connection with a browser directly from the same
box? Does your code do anything in terms of proxies which could be the
cause of the problem?
 
The resolution of this problem is more then just stupid:
I forgot to turn ba firewall back on after a test. So WITHOUT the firewall
the connection failed. Turning it on made everything work fine :))
 
Back
Top