How to use proxy with C# application

前端 未结 2 1629
余生分开走
余生分开走 2021-02-04 20:08

I am using Microsoft Visual Studio 2010 C# .net 4.0

I have a webbrowser element. What i want to do is navigating via Webbrowser element with using proxy. How can i do th

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 20:27

    The browser control is just an instance of IE - it will use IE's proxy settings. You can set these by playing with registry keys if you must do it in code.

            string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
            string serverName = "";//your proxy server name;
            string port = ""; //your proxy port;
            string proxy = serverName + ":" + port;
    
            RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
            RegKey.SetValue("ProxyServer", proxy);
            RegKey.SetValue("ProxyEnable", 1);
    

    See this: http://social.msdn.microsoft.com/forums/en-US/winforms/thread/da510380-9571-4fcd-a05f-b165ced45017/

    Update: Looks like this can be done for just the control and not the entire machine. See this code sample for setting the proxy for just a single process - http://blogs.msdn.com/b/jpsanders/archive/2011/04/26/how-to-set-the-proxy-for-the-webbrowser-control-in-net.aspx

提交回复
热议问题