WebRequest.GetResponse() = error (407) Proxy Authentication Required
-
I'm following this example: http://www.geekpedia.com/tutorial179\_Creating-a-download-manager-in-Csharp.html it seems like a really straight-forward tutorial, however, the line "webResponse = (HttpWebResponse)webRequest.GetResponse();" always gives a (407) Proxy Authentication Required exception. What can I do to make my app pick up the same authentication that Internet Explorer uses ? Note: Internet Explorer LAN settings is set to: Checked "Use automatic configuration script" Address: http://xxxxxxxxxxxxxx.yyyyy.zzzzzzz.net/proxy.pac
-
I'm following this example: http://www.geekpedia.com/tutorial179\_Creating-a-download-manager-in-Csharp.html it seems like a really straight-forward tutorial, however, the line "webResponse = (HttpWebResponse)webRequest.GetResponse();" always gives a (407) Proxy Authentication Required exception. What can I do to make my app pick up the same authentication that Internet Explorer uses ? Note: Internet Explorer LAN settings is set to: Checked "Use automatic configuration script" Address: http://xxxxxxxxxxxxxx.yyyyy.zzzzzzz.net/proxy.pac
Have a look at WebProxy[^] class. After you created the
WebProxy
instance, supply that to HttpWebRequest.Proxy[^] :)Navaneeth How to use google | Ask smart questions
-
Have a look at WebProxy[^] class. After you created the
WebProxy
instance, supply that to HttpWebRequest.Proxy[^] :)Navaneeth How to use google | Ask smart questions
GetDefaultProxy() sounds like a dream come true since I don't want the user to have to hassle with copy and pasting their proxy IP and port into my "settings" form. Additionally, I don't want the responsibility of storing their details in an encrypted file. However, GetDefaultProxy() is now antiquated. Also, using UseDefaultCredentials = true doesn't work. Is there an alternate solution to using GetDefaultProxy() ? Maybe reading the registry ?
-
GetDefaultProxy() sounds like a dream come true since I don't want the user to have to hassle with copy and pasting their proxy IP and port into my "settings" form. Additionally, I don't want the responsibility of storing their details in an encrypted file. However, GetDefaultProxy() is now antiquated. Also, using UseDefaultCredentials = true doesn't work. Is there an alternate solution to using GetDefaultProxy() ? Maybe reading the registry ?
WebRequest.GetSystemWebProxy() doesn't work either. I still get the 407 error. i.e. webRequest = (HttpWebRequest)WebRequest.Create(strURL); webRequest.Credentials = CredentialCache.DefaultCredentials; IWebProxy wp = WebRequest.GetSystemWebProxy(); webRequest.Proxy = wp;
-
Have a look at WebProxy[^] class. After you created the
WebProxy
instance, supply that to HttpWebRequest.Proxy[^] :)Navaneeth How to use google | Ask smart questions
through trial-and-error I finally got it solved. On my journey I've noticed that MANY people have problems with this, so no doubt this code will be copied plenty:
public string GetWebPage(string strURL) { //stores the html returned by the server string strResult = ""; //build the http request HttpWebRequest webRequest; webRequest = (HttpWebRequest)WebRequest.Create(strURL); IWebProxy proxy = WebRequest.GetSystemWebProxy(); proxy.Credentials = CredentialCache.DefaultCredentials; webRequest.Proxy = proxy; webRequest.Method = "GET"; webRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)"; webRequest.Timeout = -1; //initiate contact with the server HttpWebResponse webResponse; webResponse = (HttpWebResponse)webRequest.GetResponse(); //download the HTML using (StreamReader sr = new StreamReader(webResponse.GetResponseStream())) { //read the html strResult = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } return strResult; }
-
through trial-and-error I finally got it solved. On my journey I've noticed that MANY people have problems with this, so no doubt this code will be copied plenty:
public string GetWebPage(string strURL) { //stores the html returned by the server string strResult = ""; //build the http request HttpWebRequest webRequest; webRequest = (HttpWebRequest)WebRequest.Create(strURL); IWebProxy proxy = WebRequest.GetSystemWebProxy(); proxy.Credentials = CredentialCache.DefaultCredentials; webRequest.Proxy = proxy; webRequest.Method = "GET"; webRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)"; webRequest.Timeout = -1; //initiate contact with the server HttpWebResponse webResponse; webResponse = (HttpWebResponse)webRequest.GetResponse(); //download the HTML using (StreamReader sr = new StreamReader(webResponse.GetResponseStream())) { //read the html strResult = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } return strResult; }
this is also not working boss.M getting error
-
Have a look at WebProxy[^] class. After you created the
WebProxy
instance, supply that to HttpWebRequest.Proxy[^] :)Navaneeth How to use google | Ask smart questions
Hi, not sure if you're still struggling with this. Maybe this could help... I was looking at a solution to call a web service from behind a company firewall, but I didn't want to code any proxy settings nor user credentials in my app. The app should simply use my default IE proxy settings. I'm using .Net 2.0 and here's the C# code to make it work.
IWebProxy oProxy = WebRequest.GetSystemWebProxy(); oProxy.Credentials = (System.Net.NetworkCredential)CredentialCache.DefaultCredentials; "your WS stub".Proxy = oProxy;
Hope this helps. -
through trial-and-error I finally got it solved. On my journey I've noticed that MANY people have problems with this, so no doubt this code will be copied plenty:
public string GetWebPage(string strURL) { //stores the html returned by the server string strResult = ""; //build the http request HttpWebRequest webRequest; webRequest = (HttpWebRequest)WebRequest.Create(strURL); IWebProxy proxy = WebRequest.GetSystemWebProxy(); proxy.Credentials = CredentialCache.DefaultCredentials; webRequest.Proxy = proxy; webRequest.Method = "GET"; webRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)"; webRequest.Timeout = -1; //initiate contact with the server HttpWebResponse webResponse; webResponse = (HttpWebResponse)webRequest.GetResponse(); //download the HTML using (StreamReader sr = new StreamReader(webResponse.GetResponseStream())) { //read the html strResult = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } return strResult; }
I get the Proxy Authentication only when using NUnit; the same code works fine when invoked in the real environment. Anyway, adding the following lines makes it work in NUnit: IWebProxy proxy = WebRequest.GetSystemWebProxy(); proxy.Credentials = (System.Net.NetworkCredential)CredentialCache.DefaultCredentials; request.Proxy = proxy;