Use a proxy with webBrowser control C#/.net 3.5

送分小仙女□ 提交于 2019-11-30 14:23:50

Perhaps this link is useful:

http://blogs.msdn.com/b/jpsanders/archive/2011/04/26/how-to-set-the-proxy-for-the-webbrowser-control-in-net.aspx

I tested the code and it seemed to work. But two points are important:

  • It's not compatible to projects in compile mode "Any CPU" (x86 works fine)
  • JUST for HTTP proxy servers ; not for SOCKS

1- I guess webBrowser control checks the proxy only while its is created, so create a new control after setting the proxy

2- Navigate is not a blocking call and does not wait till page it loaded, use webBrowser.DocumentCompleted event

Below code should work (Not tested)

void Exec(string proxy,string url)
{
    var th = new Thread(() =>
    {
        SetProxy(proxy);
        using (WebBrowser wb = new WebBrowser())
        {
            wb.DocumentCompleted += (sndr, e) =>
            {
                ExecuteRoutine();
                Application.ExitThread();
            };
            wb.Navigate(url);
            Application.Run();
        }
    });
    th.SetApartmentState(ApartmentState.STA);
    th.Start();
    th.Join();
}
Uwe Keim

I had a somewhat similar question in the past. The accepted answer for the question suggests to take a look at this Microsoft Knowledge Base article:

"How to programmatically query and set proxy settings under Internet Explorer"

Basically, you have to do some P/Invoke and call some WinInet DLL functions. Although I never tried it in a real-world project, I strongly assume that this is the way to go.

Erx_VB.NExT.Coder

Just to let you all know, this guy has posted 5 question, all asking the same thing, and based on his first question and how badly he was knocked down, it seems he is trying to commit some type of cybercrime. Now, based on my reading of his intellect, he'll probably end up in prison really quickly, but I'm just thinking perhaps we can save him from that by letting him know that it's not possible to provide an imaginary IP address to services you are communicating with (since if you did, the service will not be able to reach you to provide a response). Here is his entertaining list:

https://stackoverflow.com/questions/12045317/how-to-hide-my-ip-address-c-net-3-5

Use a proxy with webBrowser control C#/.net 3.5

how to pass ip-address to webBrowser control

how to use custom ip address to browse a web page c#/.net

https://stackoverflow.com/questions/12019890/how-to-load-webpage-using-user-provided-ipaddress-webbrowser-control-c-net

And now, I think he has created a new username, user1563019, with more proxy/settings questions below: https://stackoverflow.com/users/1563019/user1563019

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!