By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,481 Members | 3,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,481 IT Pros & Developers. It's quick & easy.

WebClient issue connection closed...

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Gary Short" <gs****@scotlandonline.co.uk> wrote in message
news:d3**************************@posting.google.c om...
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

Nov 15 '05 #2

P: n/a
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:<#h**************@TK2MSFTNGP10.phx.gbl>...
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]
- mv*@spam.guard.caspershouse.com

"Gary Short" <gs****@scotlandonline.co.uk> wrote in message
news:d3**************************@posting.google.c om...
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

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.