how to pass ip-address to webBrowser control

2019-03-05 03:35发布

问题:

How to pass IPAddress to webBrowser control

This is my code but i don't know how to pass ip-address to webBrowser control.

IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (string line in File.ReadAllLines("proxy.txt"))
{
    IPAddress ip = IPAddress.Parse(line);
    if (ip.AddressFamily.ToString() == "InterNetwork")
    {
        localIP = ip.ToString();
        textBox1.Text = ip.ToString();

        // This code doesn't work, it's just a hypothetical example:
        webBrowser1.SourceIPAddress=ip; 

        webBrowser1.Navigate(textBox2.Text);
    }
}

this is how i want to pass ip-address to webBrowser control

//The code doesn't work, it's just a hypothetical example:
webBrowser1.SourceIPAddress = ip;

回答1:

Just Write in your textbox http://74.125.236.211

or

textBox2.Text="http://74.125.236.211"


回答2:

What you really want to do isn't clear to me but I'll take a wild guess, assuming you want the download the url in textBox2.Text using a proxy server and want to try proxies in file proxy.txt until one sucessfully works.

foreach (var proxy in File.ReadAllLines("proxy.txt"))
{
    try
    {
        using (var wc = new WebClient())
        {
            wc.Proxy = new WebProxy(proxy);
            string page wc.DownloadString(textBox2.Text);
            return page;
        }
    }
    catch { }
}