简体   繁体   中英

HttpWebRequest doesnt not use default IE proxy with credentials

On Windows 7 I put a proxy in Internet Options settings. This proxy requires authentication that being asked in IE, then I put (and save) the credentials and then I'm able to access the web. But when I use this code I get WebException: (407) Proxy Authentication Required.

var request = WebRequest.Create(@"https://google.com");
var res = request.GetResponse();

I see in debug that the WebRequest is getting the default proxy uri and port but for some reason it doesn't do the authentication. neither from saved Windows Credentials nor by poping a window to ask for credentials.

I also tried to set it implicitly with this code and got the same 407:

var systemProxy = WebRequest.GetSystemWebProxy();
var systemProxyUri = systemProxy.GetProxy(new Uri("http://www.google.com"));
var sysWebProxy = new WebProxy(systemProxyUri) { UseDefaultCredentials = true };
WebRequest.DefaultWebProxy = sysWebProxy;

What do I miss? How can I define WebRequest to use the default system's proxy with the saved credentials? or at least make windows to ask for credentials?

I cant use the app.config and don't want to put credentials hard coded.

no it does not !

if you code a programm, display a popup and ask for credentials

IWebProxy proxy = WebRequest.DefaultWebProxy;
        proxy.Credentials = new NetworkCredential(proxyLogin.Text, proxyPassword.Password);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM