0

I am trying to submit an HTTP request but I am behind a proxy. I am trying to auto configure the proxy as you see in the code below but I get a 404 not found as a response. I am guessing something about the proxy configuration is not correct. Any ideas?

WebProxy proxy = new WebProxy("http://companyproxy.com/proxy.pac");   
proxy.UseDefaultCredentials = true;  
WebRequest request = WebRequest.Create
("http://weather.noaa.gov/pub/data/observations/metar/stations/LGSO.TXT");
request.Proxy = proxy;
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response = request.GetResponse();
response.Close();

I have tried using default credentials for the proxy as well as my own network credentials but i get the same error.

EDIT: Tried this approach having the IE proxy configured in Settings > Connections > LAN

WebRequest request = WebRequest.Create
("http://weather.noaa.gov/pub/data/observations/metar/stations/LGSO.TXT");
request.Proxy = WebRequest.GetSystemWebProxy();
request.Credentials = CredentialCache.DefaultCredentials; ;
WebResponse response = request.GetResponse();

Now I get proxy (407) Proxy Authentication Required.

jayt.dev
  • 975
  • 6
  • 14
  • 36
  • You should set credentials on `proxy` object. Check [this](http://code.logos.com/blog/2010/01/using_http_proxy_servers.html) article... – csharpfolk Sep 26 '13 at 07:04
  • I tried using the default credentials for the proxy as suggested in the article because the proxy is configured in IE > Connections > LAN but I still get 404 – jayt.dev Sep 26 '13 at 07:28

3 Answers3

1

Finally it worked with the following:

IWebProxy myProxy = WebRequest.DefaultWebProxy;
myProxy.Credentials = new NetworkCredential(username, password);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestURL);          
request.Proxy = myProxy;
jayt.dev
  • 975
  • 6
  • 14
  • 36
0

See if this works.

WebRequest request = WebRequest.Create("http://weather.noaa.gov/pub/data/observations/metar/stations/LGSO.TXT");

WebResponse response = request.GetResponse();
response.Close();

I too live behind a proxy, this above code is working just fine for me.

Did you see this? Proxy Basic Authentication in C#: HTTP 407 error

Community
  • 1
  • 1
0

If the proxy settings are inserted in IE and the program is running under the user that can pass the proxy settings would it be fine if you just change

request.Credentials = CredentialCache.DefaultCredentials;

TO

request.Credentials = CredentialCache.DefaultNetworkCredentials;

These are the only 2 lines i use: request.UseDefaultCredentials = true; request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

If you are running your program under an not allowed user of the proxy server or a build-in system account, you should use a possibillity where the user can insert his proxy settings.

Kind regards, Condra963