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;
}