none
Unable to get the Internet Explorer proxy settings using WebRequest.GetSystemWebProxy() RRS feed

  • Question

  • I'm using "WebRequest.GetSystemWebProxy()" method to get the proxy settings configured in the Internet Explorer. It works successfully in most of the systems. In some system the same method was not detecting the proxy settings available in the system.

    My code is,

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);IWebProxy iproxy = WebRequest.GetSystemWebProxy();iproxy.Credentials = CredentialCache.DefaultCredentials;req.Proxy = iproxy;

    Note:

           My application will use the highest .Net framework installed in the system. This issue arises in Windows 7 with Internet Explorer 10

    Thursday, November 23, 2017 5:44 AM

All replies

  • Hi Bharath.rb,

    Is it the same version of Internet Explorer with the another system which works successfully?

    I will create a Windows 7 with Internet Explorer 10 to test the method to get the proxy settings configured in the Internet Explorer. It takes times. If I have something new, I will feedback as soon as possible.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 24, 2017 8:54 AM
    Moderator
  • Maybe you can test if it works with WinHTTP APIs.

    Like :

    [StructLayout(LayoutKind.Sequential)]
    public struct WINHTTP_CURRENT_USER_IE_PROXY_CONFIG
    {
        [MarshalAs(UnmanagedType.Bool)]
        bool fAutoDetect;
        [MarshalAs(UnmanagedType.LPWStr)]
        string lpszAutoConfigUrl;
        [MarshalAs(UnmanagedType.LPWStr)]
        string lpszProxy;
        [MarshalAs(UnmanagedType.LPWStr)]
        string lpszProxyBypass;
    }
    
    [DllImport("Winhttp.dll", SetLastError = true)]
          static extern bool WinHttpGetIEProxyConfigForCurrentUser(ref WINHTTP_CURRENT_USER_IE_PROXY_CONFIG pProxyConfig);
    
    WINHTTP_CURRENT_USER_IE_PROXY_CONFIG IEProxyConfig = new WINHTTP_CURRENT_USER_IE_PROXY_CONFIG();
    WinHttpGetIEProxyConfigForCurrentUser(ref IEProxyConfig);

    Friday, November 24, 2017 5:55 PM
  • Thanks for the reply,   I was not able to change the code, because the same code was working good in most of the system and only few systems get this issue.

    I also tried with the command "netsh winhttp import proxy source =ie" which shows "No proxy" on not working systems and shows the Proxy server ip for working systems.

    Monday, November 27, 2017 5:27 AM
  • Hi Bharath.rb,

    Thank you for feedback.

    I create the Win7 to test the code. There is no compiler error for me.

    >>I was not able to change the code, because the same code was working good in most of the system and only few systems get this issue.

    What is the issue? Please provide more details.

    >>HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);

    What is the URL you used for?

    Please provide more information, I will try to reproduce your error.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 28, 2017 8:27 AM
    Moderator
  • HttpWebRequest req = (HttpWebRequest)WebRequest.Create("www.google.com");IWebProxy iproxy = WebRequest.GetSystemWebProxy();iproxy.Credentials = CredentialCache.DefaultCredentials;req.Proxy = iproxy;

    I'm reading the system proxy using 

    WebRequest.GetSystemWebProxy();

    And I'm displaying the request uri using

    Console.WriteLine("Request URL : " + iproxy.GetProxy(req.RequestUri));

    The above writeline will print the proxy address if the system has proxy configuration. But in some systems eventhough proxy is configured, it displays "www.google.com"as the request url.

    WebResponse resp = (HttpWebResponse)req.GetResponse();

    The above line through an exception as "Remote server not respond for the long time", only when the "www.google.com" displays as the request url.

    While in the browser google is working.

    Monday, December 4, 2017 2:02 PM