How do I find out the browser's proxy settings?

前端 未结 4 910
既然无缘
既然无缘 2020-12-01 02:48

I am writing a command-line tool for Windows that uses libcurl to download files from the internet.

Obviously, the downloading doesn\'t work when the user is behind

4条回答
  •  旧巷少年郎
    2020-12-01 03:32

    Here is a complete code sample how to call WinHttpGetIEProxyConfigForCurrentUser method from winhttp.dll library in C#

    [TestClass]
    public class UnitTest1
    {
        [StructLayout(LayoutKind.Sequential)]
        public struct WinhttpCurrentUserIeProxyConfig
        {
            [MarshalAs(UnmanagedType.Bool)]
            public bool AutoDetect;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string AutoConfigUrl;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string Proxy;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string ProxyBypass;
    
        }
    
        [DllImport("winhttp.dll", SetLastError = true)]
        static extern bool WinHttpGetIEProxyConfigForCurrentUser(ref WinhttpCurrentUserIeProxyConfig pProxyConfig);
    
        [TestMethod]
        public void TestMethod1()
        {
            var config = new WinhttpCurrentUserIeProxyConfig();
    
            WinHttpGetIEProxyConfigForCurrentUser(ref config);
    
            Console.WriteLine(config.Proxy);
            Console.WriteLine(config.AutoConfigUrl);
            Console.WriteLine(config.AutoDetect);
            Console.WriteLine(config.ProxyBypass);
        }
    }
    

提交回复
热议问题