HttpWebRequest fails

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!
 
J

Jon Skeet [C# MVP]

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?
 
G

Guest

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 :))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top