2

I found several questions about this but they seem to resolve windows authentication. I have custom users and passwords and this code works with other existing proxies. Now since a week we use new proxy servers that use {Basic realm="Private Proxies - Password Auth"} and the code does not work.

        var user = "********";
        var pass = "********";
        var port = "********";
        var ip = "********";
        var url = "********";
        var baseUrl = "********";

        NetworkCredential cr = new NetworkCredential(user, pass);
        cr.Domain = ip;

        WebProxy proxy = new WebProxy(ip + ":" + port) { BypassProxyOnLocal = false, Credentials = cr, UseDefaultCredentials = false};

        HttpClientHandler handler = new HttpClientHandler();

        handler.Proxy = proxy;
        handler.UseProxy = true;

        HttpClient httpClient = new HttpClient(handler);
        httpClient.BaseAddress = new Uri(baseUrl);

        var result = httpClient.GetAsync(url).Result;

        Console.WriteLine(result.Content.ReadAsStringAsync().Result);
        Console.Read();

I have tested the credentials with Firefox and there the proxies work after I provide the credentials in a popup. I set the NetworkCredential inside the proxy, but when I do a request it just returns 407: Proxy Authentication Required.

I tried to set the Proxy-Authorization header manually. It still does not work.

enter image description here

Does anyone know how to fix this!?

botenvouwer
  • 4,334
  • 9
  • 46
  • 75

1 Answers1

0

You need to fill Proxy-Authorization header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization

Also, look at this question: Proxy Basic Authentication in C#: HTTP 407 error

astef
  • 8,575
  • 4
  • 56
  • 95
  • I tried to set the header manually in multiple ways. It stil does not work. I'm currently trying to capture the http request to see if it is actually set. – botenvouwer Jun 11 '18 at 11:11