Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need some help from someone who has already use the webBrowser control along with a proxys.

What I need is the following.

1 - Set a proxy for a webBrowser control. 2 - Load a specific site. 3 - Execute a routine over the site. 4 - Set a diferent proxy for the webBrowser control. 5 - Load another site. 6 - Execute the same routine from point number 3.

And the process keeps in that way, looping from a list of proxys, until all of them had been used.

But. I'm having some problems with the app. to do that:

1 - I'm using the code attached to set the proxy into the webBrowser control, but seems to work only once during the execution, when I call it again in the loop it just doesn't work, I can get t ounderstand why.

2 - I'm having problems to determine when the page has loaded completely, I mean, when I set the first site to load, I need the program to wait until it has finish to load, and after that execute the routine over it, and continue with the process.

Hope some one could help me with this...

/// The function that I'm using -----------------------------

    private void SetProxy(string Proxy)
    {

        MessageBox.Show("Setting :" + Proxy);
        string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";

        RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
        RegKey.SetValue("ProxyServer", Proxy);
        RegKey.SetValue("ProxyEnable", 1);

    }

// The app logic --------------------------------------

        SetProxy("190.97.219.38:80");
        webBrowser1.Navigate("http://www.whatismyip.com/");
        ExecuteRoutine();

        SetProxy("187.93.77.235:80");
        webBrowser1.Navigate("http://www.whatismyip.com/");
        ExecuteRoutine();

        SetProxy("109.235.49.243:80");
        webBrowser1.Navigate("http://www.whatismyip.com/");
        ExecuteRoutine();
like image 658
user1608298 Avatar asked Aug 20 '12 17:08

user1608298


1 Answers

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
like image 161
P. R. 117 Avatar answered Oct 20 '22 21:10

P. R. 117