Proxy Basic Authentication in C#: Http 407 Error

Proxy Basic Authentication in C#: HTTP 407 error

here is the correct way of using proxy along with creds..

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);

IWebProxy proxy = request.Proxy;
if (proxy != null)
{
Console.WriteLine("Proxy: {0}", proxy.GetProxy(request.RequestUri));
}
else
{
Console.WriteLine("Proxy is null; no proxy will be used");
}

WebProxy myProxy = new WebProxy();
Uri newUri = new Uri("http://20.154.23.100:8888");
// Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
myProxy.Address = newUri;
// Create a NetworkCredential object and associate it with the
// Proxy property of request object.
myProxy.Credentials = new NetworkCredential("userName", "password");
request.Proxy = myProxy;

Thanks everyone for help... :)

Error 407 (Proxy Authentication Request) on Web Request via Geocoding API

Since it is throwing an error regarding proxy, you can try setting your proxy details to GoogleGeocoder class.

GoogleGeocoder geocoder = new GoogleGeocoder
{
Proxy = new WebProxy
{
Address = new Uri("proxy url"),
Credentials = new NetworkCredential("username", "password")
}
};

C# 407 Proxy Authentication Required

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.

HTTP 407 (Proxy Authentication Required)

It's a challenge/response protocol. Usually, the client makes an initial request without any authentication headers (you may set request.PreAuthenticate = true to send the credentials with the first request).

Then, the server responds with a list of authentication methods that it supports.

If the user did not explicitly specify an authentication method using CredentialsCache, the runtime will try them all, from strongest to weakest. Some protocols (NTLM, for instance) require multiple requests from client to server. In theory, Digest should work with a single one, no idea why it's sending the request twice.

Regarding your proxy question, there are two different kinds of authentication:

  1. The target web server's authentication, a proxy simply passes this though and you don't need any special code in your client.
  2. In addition to that, the proxy itself may also require authentication - which may be different from the one of target web server.

You specify these using

var proxy = new WebProxy ("http://localhost:3128/");
proxy.Credentials = new NetworkCredential ("username", "password");

and then

WebRequest.DefaultWebProxy = proxy;

or

request.Proxy = proxy;

Don't set any credentials on the WebProxy if your proxy server doesn't use any authentication.

If you can't get authentication working while using a proxy server, look at the actual requests that are being sent between the three parties (web server, proxy, client) with Wireshark.

HTTP 407 proxy authentication error when calling a web service

I think I will have to write off this question. My original posted code does appear to work sometimes. Our proxy server is extremely unreliable; one minute it will block an internet connection from any software, and the next it will allow it. The IT guys seem powerless to do anything about it, and we (everyone outside the IT department) have no authority to make changes to the network infrastructure.

If anyone has any ideas on how to "harden" my code to compensate for an unreliable proxy server, then I'd be interested to hear them. :-)

Web Request error 407 Proxy Authentication Required

try with adding proxy credentials to request and also give network credentials

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
request.Credentials = new NetworkCredential("username", "pw");

WebProxy webProxy = new WebProxy("http://myproxy.net:8080/", true)
{
Credentials = new NetworkCredential("username", "pw"),
UseDefaultCredentials = false
};

request.Proxy = webProxy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

//rest of the code...

Edit

For requests that you create, you can disable automatic proxy detection at the request level by using a null Proxy with your request

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
request.Proxy = null;
//rest of the code


Related Topics



Leave a reply



Submit