bizimunda
bizimunda

Reputation: 1035

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>

Upvotes: 5

Views: 21018

Answers (1)

Alberto Chiesa
Alberto Chiesa

Reputation: 7360

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.

Upvotes: 9

Related Questions