Question

I have a REST-based web service I'm trying to connect to, and while it works just fine from my local dev machine, I am trouble getting it to work on my client's test system which is behind a web proxy.

I have this code snippet here:

HttpWebRequest request = WebRequest.Create(targetUrl) as HttpWebRequest;

if (request == null)
   return;

request.Method = "GET";
request.Accept = "application/json";

request.Credentials = new NetworkCredential("myusername", "mytopsecretpassword");

WebProxy webProxy = new WebProxy("myproxy.net", 8080)
         {
             Credentials = new NetworkCredential("myusername", "mytopsecretpassword"),
             UseDefaultCredentials = false
         };

request.Proxy = webProxy;

But when I try to execute this call and get back the response like this:

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

I keep getting an error:

System.Net.WebException
The remote server returned an error: (407) Proxy Authentication Required.

WTF ?!?! I'm setting up my proxy and I'm providing the proxy credentials.... what more can I do?

Was it helpful?

Solution

Try adding the domain to the proxy credentials.

I'd also try setting UseDefaultCredentials = false before you set the new credentials.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top