/// <summary> /// 从IWebProxy实例转换获得 /// </summary> /// <param name="webProxy">IWebProxy</param> /// <param name="targetAddress">目标url地址</param> /// <exception cref="ArgumentNullException"></exception> /// <returns></returns> public static HttpProxy FromWebProxy(IWebProxy webProxy, Uri targetAddress) { if (webProxy == null) { throw new ArgumentNullException(nameof(webProxy)); } if (targetAddress == null) { throw new ArgumentNullException(nameof(targetAddress)); } var proxyAddress = webProxy.GetProxy(targetAddress); var httpProxy = new HttpProxy(proxyAddress); httpProxy.SetCredentialsByInterface(webProxy.Credentials); return(httpProxy); }