public HttpClientPro(ProxyIdentity identity) : this(CreateHandler(identity), true) { Identity = identity; DefaultRequestHeaders.UserAgent.Clear(); if (!string.IsNullOrEmpty(identity.UserAgent)) { DefaultRequestHeaders.UserAgent.ParseAdd(identity.UserAgent); } }
private static HttpMessageHandler CreateHandler(ProxyIdentity identity) { if(identity == null) throw new ArgumentNullException(nameof(identity)); var proxy = identity.Credential != null ? new WebProxy(identity.Proxy, true, null, identity.Credential) : new WebProxy(identity.Proxy); proxy.UseDefaultCredentials = identity.Credential != null; return new HttpClientHandler { UseProxy = true, Proxy = proxy }; }