internal static IEnumerable <Uri> getProxiesForUrl( Uri requestUrl, string userAgent) { IntPtr hHttpSession = IntPtr.Zero; string[] proxyList = null; ; try { hHttpSession = WinHttpOpen(userAgent, AccessType.NoProxy, null, null, 0); if (hHttpSession != IntPtr.Zero) { AutoProxyOptions autoProxyOptions = new AutoProxyOptions(); autoProxyOptions.Flags = AccessType.AutoDetect; autoProxyOptions.AutoLogonIfChallenged = true; autoProxyOptions.AutoDetectFlags = AutoDetectType.Dhcp | AutoDetectType.DnsA; ProxyInfo proxyInfo = new ProxyInfo(); if (WinHttpGetProxyForUrl(hHttpSession, requestUrl.ToString(), ref autoProxyOptions, ref proxyInfo)) { if (!string.IsNullOrEmpty(proxyInfo.Proxy)) { proxyList = proxyInfo.Proxy.Split(';', ' '); } } } } catch (System.DllNotFoundException) { // winhttp.dll is not found. } catch (System.EntryPointNotFoundException) { // A method within winhttp.dll is not found. } finally { if (hHttpSession != IntPtr.Zero) { WinHttpCloseHandle(hHttpSession); hHttpSession = IntPtr.Zero; } } if (proxyList != null && proxyList.Length > 0) { Uri proxyUrl; foreach (string address in proxyList) { if (tryCreateUrlFromPartialAddress(address, out proxyUrl)) { yield return(proxyUrl); } } } }
internal static IEnumerable<Uri> GetProxiesForUrl( Uri requestUrl, string userAgent) { IntPtr hHttpSession = IntPtr.Zero; string[] proxyList = null; ; try { hHttpSession = WinHttpOpen(userAgent, AccessType.NoProxy, null, null, 0); if (hHttpSession != IntPtr.Zero) { AutoProxyOptions autoProxyOptions = new AutoProxyOptions(); autoProxyOptions.Flags = AccessType.AutoDetect; autoProxyOptions.AutoLogonIfChallenged = true; autoProxyOptions.AutoDetectFlags = AutoDetectType.Dhcp | AutoDetectType.DnsA; ProxyInfo proxyInfo = new ProxyInfo(); if (WinHttpGetProxyForUrl(hHttpSession, requestUrl.ToString(), ref autoProxyOptions, ref proxyInfo)) { if (!string.IsNullOrEmpty(proxyInfo.Proxy)) { proxyList = proxyInfo.Proxy.Split(';', ' '); } } } } catch (System.DllNotFoundException) { // winhttp.dll is not found. } catch (System.EntryPointNotFoundException) { // A method within winhttp.dll is not found. } finally { if (hHttpSession != IntPtr.Zero) { WinHttpCloseHandle(hHttpSession); hHttpSession = IntPtr.Zero; } } if (proxyList != null && proxyList.Length > 0) { Uri proxyUrl; foreach (string address in proxyList) { if (TryCreateUrlFromPartialAddress(address, out proxyUrl)) { yield return proxyUrl; } } } }
private static extern bool WinHttpGetProxyForUrl( IntPtr hSession, string url, [In] ref AutoProxyOptions autoProxyOptions, [In, Out] ref ProxyInfo proxyInfo);