I had the same problem maybe two weeks ago !! HTTP errors 407. I tried both sentences, set the network credentials, and added the default proxy line to app.config, but it didn’t work. Strange, because I did not have this problem in a vb application that I wrote last year that did the same, go to the website and download the source as a string. When I did this, I ran into this problem, but adding the defaultProxy line to App.config! Weird
This is how I got around this problem.
I do not create a proxy, I assign the default (pulled from app.config) proxy webRequest attribute. Then I guarantee that the "UseDefaultCredentials" parameter is set to "true".
HttpWebRequest request = (HttpWebRequest.Create(m.Url) as HttpWebRequest); request.Proxy = WebRequest.DefaultWebProxy; request.UseDefaultCredentials = true;
I added this to app.config (same as above).
<system.net> <defaultProxy useDefaultCredentials="true"/> </system.net>
Here is a kicker (and I would like to explain why this solved my problem). Right after creating the request and assigning the proxy with the correct credentials ... I had to create a cookie container and assign it to my web request. Seriously, I don’t know why this solved this problem because I didn’t have to do this before.
CookieContainer cc = new CookieContainer(); request.CookieContainer = cc;
Hope this helps you.
Here's the full code (minus the app.config line):
HttpWebRequest request = (HttpWebRequest.Create(m.Url) as HttpWebRequest); request.Proxy = WebRequest.DefaultWebProxy; request.UseDefaultCredentials = true; CookieContainer cc = new CookieContainer(); request.CookieContainer = cc; HttpWebResponse response = (request.GetResponse() as HttpWebResponse);
source share