Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# 407 Proxy Authentication Required

Tags:

c#

c#-4.0

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>
like image 341
bizimunda Avatar asked Feb 04 '23 23:02

bizimunda


1 Answers

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.

like image 165
A. Chiesa Avatar answered Feb 08 '23 15:02

A. Chiesa