WebClient issue connection closed...

  • Thread starter Thread starter Gary Short
  • Start date Start date
G

Gary Short

Hello group,

I was wondering if anyone here could help me with an odd WebClient
problem. When I run the following code:

WebClient aWebClient = new WebClient();
Byte[] aBA = aWebClient.DownloadData("http://www.microsoft.com");
string strContent = Encoding.ASCII.GetString(aBA);

Everything works as expected. However, when I run the following code:

string strURL = "http://www.microsoft.com"
WebClient aWebClient = new WebClient();
Byte[] aBA = aWebClient.DownloadData(strURL);
string strContent = Encoding.ASCII.GetString(aBA);

It fails with the error "The underlying connection was closed: unable
to connect to the remote server". Except for the code change
everything's the same. I'm aware of the KB stuff about proxy etc, but
there's no proxy here to worry about. The same behaviour is exhibited
at work and at home.

What's going on?

Cheers,
Gary
 
Gary,

Are you running these two sections of code right after another, or are
you running them in different programs?

Obviously, there should be no difference, and I can not find any errors
with your code. I've tried it myself, and it works the same either way.
Can you give more details, and actual code if the example you gave was not
the real code?
 
Hello Nicholas,

Thanks for getting back to me. I believe the problem was to do with a
DNS server somewhere, though quite why it would manifest itself in
quite this manner is beyond me. I received an emial from my ISP
telling me there were DNS problems and sure enough today it's working
fine.

I'm still a little confused as to what the problem was, but at least
it's sorted now.

Thanks again for your input.

Cheers,
Gary


Nicholas Paldino said:
Gary,

Are you running these two sections of code right after another, or are
you running them in different programs?

Obviously, there should be no difference, and I can not find any errors
with your code. I've tried it myself, and it works the same either way.
Can you give more details, and actual code if the example you gave was not
the real code?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Gary Short said:
Hello group,

I was wondering if anyone here could help me with an odd WebClient
problem. When I run the following code:

WebClient aWebClient = new WebClient();
Byte[] aBA = aWebClient.DownloadData("http://www.microsoft.com");
string strContent = Encoding.ASCII.GetString(aBA);

Everything works as expected. However, when I run the following code:

string strURL = "http://www.microsoft.com"
WebClient aWebClient = new WebClient();
Byte[] aBA = aWebClient.DownloadData(strURL);
string strContent = Encoding.ASCII.GetString(aBA);

It fails with the error "The underlying connection was closed: unable
to connect to the remote server". Except for the code change
everything's the same. I'm aware of the KB stuff about proxy etc, but
there's no proxy here to worry about. The same behaviour is exhibited
at work and at home.

What's going on?

Cheers,
Gary
 
Back
Top