private static void RefreshProxySettings(string strProxy) { InternetProxyInfo ipi; // Filling in structure if (!string.IsNullOrEmpty(strProxy)) { ipi = new InternetProxyInfo { dwAccessType = InternetOpenType.PROXY, proxy = strProxy, proxyBypass = "******", }; } else if (strProxy == null) { //IE Default var p = WebRequest.GetSystemWebProxy(); if (p.IsBypassed(new Uri("http://www.google.com/"))) { ipi = new InternetProxyInfo { dwAccessType = InternetOpenType.DIRECT, proxy = null, proxyBypass = null, }; } else { ipi = new InternetProxyInfo { dwAccessType = InternetOpenType.PROXY, proxy = p.GetProxy(new Uri("http://www.google.com/")).Authority, proxyBypass = "******", }; } } else { ipi = new InternetProxyInfo { dwAccessType = InternetOpenType.DIRECT, proxy = null, proxyBypass = null, }; } if (!InternetSetOption(IntPtr.Zero, InternetOption.PROXY, ref ipi, Marshal.SizeOf(ipi))) { throw new Win32Exception(); } }
private static extern bool InternetSetOption(IntPtr hInternet, InternetOption dwOption, [In] ref InternetProxyInfo lpBuffer, int lpdwBufferLength);
private static void RefreshProxySettings(string strProxy) { InternetProxyInfo ipi; // Filling in structure if (!string.IsNullOrEmpty(strProxy)) { ipi = new InternetProxyInfo { dwAccessType = InternetOpenType.PROXY, proxy = strProxy, proxyBypass = "******", }; } else if (strProxy == null) { //IE Default var p = WebRequest.GetSystemWebProxy(); if (p.IsBypassed(new Uri("http://www.google.com/"))) { ipi = new InternetProxyInfo { dwAccessType = InternetOpenType.DIRECT, proxy = null, proxyBypass = null, }; } else { ipi = new InternetProxyInfo { dwAccessType = InternetOpenType.PROXY, proxy = p.GetProxy(new Uri("http://www.google.com/")).Authority, proxyBypass = "******", }; } } else { ipi = new InternetProxyInfo { dwAccessType = InternetOpenType.DIRECT, proxy = null, proxyBypass = null, }; } if (!InternetSetOption(IntPtr.Zero, InternetOption.PROXY, ref ipi, Marshal.SizeOf(ipi))) throw new Win32Exception(); }