简体   繁体   中英

C# 407 Proxy Authentication Required

I want to make a request to a resource (that resource is behind a proxy). I have the proxy address and the port as well. I have tried with NetworkCredentialn no success, with CacheCredentials no success. WebException is:

ProtocolError
The remote server returned an error: (407) Proxy Authentification Required

I always get error at this line:

WebResponse response = request.GetResponse();

I have already done this: Package manager in Visual Studio 2015 "407 (Proxy Authentication Required)"

I tried to configure my App.config file

 <?xml version="1.0" encoding="utf-8" ?>
 <configuration>
     <system.net>
         <defaultProxy useDefaultCredentials="true" />
     </system.net>
 </configuration>

From our corporate network, we usually employ this code:

        WebProxy proxy = new WebProxy("http://your.proxy.server:8080", true);
        proxy.Credentials = new NetworkCredential("user", "password");
        WebRequest.DefaultWebProxy = proxy;

The idea is you put this code somewhere at the beginning of your program (or in the App start if you're on IIS) and then every single request will take the default proxy configuration.

No change in web.config is required. AFAICT, in web.config you cannot set the credentials.

In my experience, it works also for web services and WCF communications.

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