C# Getting proxy settings from Internet Explorer

后端 未结 2 1678
醉酒成梦
醉酒成梦 2020-12-14 12:19

i have a problem in certain company in germany. They use proxy in their network and my program cant communicate with server.

IE works with this settings:

相关标签:
2条回答
  • 2020-12-14 12:35

    Use GetSystemWebProxy to return what the system default proxy is.

        WebRequest.DefaultProxy = WebRequest.GetSystemWebProxy();
    

    But every HttpWebRequest should automatically be filled out with this information by default. For example, the following snippet in a standalone console application should print the correct information on a system with a PAC file configured.

        HttpWebRequest myWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
    
        // Obtain the 'Proxy' of the  Default browser.  
        IWebProxy proxy = myWebRequest.Proxy;
        // Print the Proxy Url to the console.
        if (proxy != null)
        {
            Console.WriteLine("Proxy: {0}", proxy.GetProxy(myWebRequest.RequestUri));
        } 
        else
        {
            Console.WriteLine("Proxy is null; no proxy will be used");
        }
    
    0 讨论(0)
  • 2020-12-14 12:46

    Use DefaultNetworkCredentials to return system proxy credentials.

    request.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
    
    0 讨论(0)
提交回复
热议问题