.NET - downloading multiple pages from a website with a single DNS query

Posted by lampak on Stack Overflow See other posts from Stack Overflow or by lampak
Published on 2010-04-23T14:15:34Z Indexed on 2010/04/23 14:33 UTC
Read the original article Hit count: 332

Filed under:
|
|
|
|

I'm using HttpRequest to download several pages from a website (in a loop). Simplifying it looks like this:

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(
            "http://sub.domain.com/something/" + someString
        );

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

//do something

I'm not quite sure actually but every request seems to resolve the address again (I don't know how to test if I'm right). I would like to boost it a little and resolve the address once and then reuse it for all requests. I can't work out how to force HttpRequest into using it, though.

I have tried using Dns.GetHostAddresses, converting the result to a string and passing it as the address to HttpWebRequest.Create. Unfortunately, server returns error 404 then. I managed to google that's probably because the "Host" header of the http query doesn't match what the server expects.

Is there a simple way to solve this?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about httprequest