WebClient issue connection closed...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Short

    #1

    WebClient issue connection closed...

    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.Down loadData("http://www.microsoft.c om");
    string strContent = Encoding.ASCII. GetString(aBA);

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

    string strURL = "http://www.microsoft.c om"
    WebClient aWebClient = new WebClient();
    Byte[] aBA = aWebClient.Down loadData(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
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: WebClient issue connection closed...

    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]
    - mvp@spam.guard. caspershouse.co m

    "Gary Short" <gshort@scotlan donline.co.uk> wrote in message
    news:d383e688.0 311171256.1ab63 0c8@posting.goo gle.com...[color=blue]
    > 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.Down loadData("http://www.microsoft.c om");
    > string strContent = Encoding.ASCII. GetString(aBA);
    >
    > Everything works as expected. However, when I run the following code:
    >
    > string strURL = "http://www.microsoft.c om"
    > WebClient aWebClient = new WebClient();
    > Byte[] aBA = aWebClient.Down loadData(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[/color]


    Comment

    • Gary Short

      #3
      Re: WebClient issue connection closed...

      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]" <mvp@spam.guard .caspershouse.c om> wrote in message news:<#h4WPDVrD HA.2480@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
      > 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]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Gary Short" <gshort@scotlan donline.co.uk> wrote in message
      > news:d383e688.0 311171256.1ab63 0c8@posting.goo gle.com...[color=green]
      > > 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.Down loadData("http://www.microsoft.c om");
      > > string strContent = Encoding.ASCII. GetString(aBA);
      > >
      > > Everything works as expected. However, when I run the following code:
      > >
      > > string strURL = "http://www.microsoft.c om"
      > > WebClient aWebClient = new WebClient();
      > > Byte[] aBA = aWebClient.Down loadData(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[/color][/color]

      Comment

      Working...