Exemplo n.º 1
0
 public HttpClientPro(ProxyIdentity identity)
     : this(CreateHandler(identity), true)
 {
     Identity = identity;
     DefaultRequestHeaders.UserAgent.Clear();
     if (!string.IsNullOrEmpty(identity.UserAgent))
     {
         DefaultRequestHeaders.UserAgent.ParseAdd(identity.UserAgent);
     }
 }
Exemplo n.º 2
0
 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
     };
 }