0

I am trying to reach some internet resource from server behind firewall. Every time i make a request I get an error from my proxy. It says I am not authenticated (HTTP 407 error code). But I am using next code (I suppose it supports proxy)

public class ProxyHttpClientFactory: HttpClientFactory {
  private readonly ICredentials _credentials;
  private readonly IWebProxy _proxy;

  public ProxyHttpClientFactory(ProxyOptions options) {
    _credentials = new NetworkCredential(options.Login, options.Password, options.ProxyUri);
    _proxy = new WebProxy {
      Address = new Uri(options.ProxyUri),
      Credentials = _credentials
    };
  }

  protected override HttpMessageHandler CreateHandler(CreateHttpClientArgs args) {
    return new CustomHandler(_proxy, _credentials);
  }
}

public CustomHandler(IWebProxy proxy, ICredentials credentials) {
  UseProxy = true;
  Proxy = proxy;
  Credentials = credentials;
  SslProtocols = SslProtocols.Tls12;
  UseCookies = false;
  ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>true;
}
V. Parshin
  • 48
  • 6
  • The firewall could be blocking the request. Network credentials probably won't work across the firewall. Is the proxy server part of you network? – jdweng Aug 04 '20 at 17:04
  • Yes, it is. I found information that i am missing some auth headers but I don't know how to add them. – V. Parshin Aug 04 '20 at 17:06
  • 1
    Did you try Default Credentials? Using a Login/Password may not work on your network. See : https://stackoverflow.com/questions/9603093/proxy-basic-authentication-in-c-http-407-error – jdweng Aug 04 '20 at 17:13
  • 1
    [Does this answer your question?](https://stackoverflow.com/a/30605900/12888024) – aepot Aug 04 '20 at 19:14
  • Guys, thanks for help. None of this solved my problem because it was in wrong NetworkCredential params. I passed proxy address as credential domain and it caused proxy auth error – V. Parshin Aug 05 '20 at 08:58

0 Answers0