views:

57

answers:

3

Hey, There are several questions like this, but my situation seems a bit different. I have extremely simple code:

WebClient client = new WebClient();
client.DownloadFile("http://www.xkcd.com", "xkcd.html");

However, I get the error "No connection could be made because target machine actively refused the connection." However, I also see this problem with connections to any website. It also only appears in .NET applications, all of a sudden, none of them can access the web. Any ideas?

A: 

The user that your code is running as is relevant. For example the code might work in a console/WinForms app but not in an ASP.NET app.

Jerome
A: 

For the purpose of a sanity check, I like using PowerShell to call api's, so I'd suggest that if you can.

Also, make sure to try that url in IE on the system just to make sure there's nothing weird going on (forced proxy, site is really down, DNS or hosts file is resolving it to something else, etc).

C:\Users\james » $wc = new-object system.net.webclient
C:\Users\james » $wc.DownloadFile("http://www.xkcd.com", "xkcd.html")
C:\Users\james » dir .\xkcd.html


    Directory: Microsoft.PowerShell.Core\FileSystem::C:\Users\james


Mode           LastWriteTime       Length Name
----           -------------       ------ ----
-a---     8/26/2010  1:08 AM         7454 xkcd.html
James Manning
A: 

Try to go to the site using Internet Explorer browser. The problem is the WebClient uses proxy settings from IE. And there are any wrong proxy settings you'll get the message you've got.

Vasiliy Borovyak
Hmm, it wouldn't go from IE either. So my problem has turned into an IE problem now.
Drew DeVault