tags:

views:

73

answers:

3

I've got a method like this:

private string getFromURL(string url)
{
    WebClient myClient = new WebClient();
    return myClient.DownloadString(url);
}

using WebClient from System.Net. It appears to be hitting the url twice (I'm also watching the log of the web server in question and it records two hits). Any idea why this might be?

EDIT: the answer was in fact programmer error. I no longer have any reason to think this is behaving strangely. Thanks for the answers.

+1  A: 

My guess is that it's doing a HEAD before the GET. Does your log show the HTTP method being used?

Jon Skeet
+2  A: 

Or if the URL is subtly different in the two cases it could be responding to a HTTP redirect request.

Kylotan
I believe this may be the case. I tried the code fetching `http://www.google.com`, inspecting the requests/responses using Fiddler, and it makes two requests; the first gets a 302 response, the second a 200.
Fredrik Mörk
+1  A: 

check out tcpmon: https://tcpmon.dev.java.net/ it's a java tool - but you can run it easy w/out being a "java" guy

Chances are there's a redirect or something to itself, so you should be able to see if the http requests are identical or slightly different.

Also, check out curl (cygwin) - you can test sending the requests from there and see if there's a redirect or something.

andersonbd1