C#-代理检查问题

时间:2018-09-04 17:15:01

标签: c# proxy httpwebrequest

我一直在尝试做一个简单的代理检查器...

WebProxy myProxy = default(WebProxy);
foreach (string proxy in Proxies)
{
    try
    {
        myProxy = new WebProxy(proxy);
        HttpWebRequest r = HttpWebRequest.Create("<a href="http://www.google.com"" rel="nofollow">http://www.google.com"</a>);
        r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36";
        r.Timeout = 3000;
        r.Proxy = myProxy;
        HttpWebResponse re = r.GetResponse();
        Console.WriteLine($"[+] {proxy} Good", ConsoleColor.Green);
    }
    catch (Exception)
    {
        Console.WriteLine($"[-] {proxy} Bad", ConsoleColor.Red);
    }
}

由于某些原因,此行:

HttpWebRequest r = HttpWebRequest.Create("<a href="http://www.google.com"" rel="nofollow">http://www.google.com"</a>);

我在http下看到一条红色的线,这是我得到的错误

The best overload for Create does not have a parameter names http

我该如何解决?而且我该如何使它真正快速地检查代理服务器,而不是像每5秒钟就有1个代理服务器

1 个答案:

答案 0 :(得分:0)

HttpWebRequest类的Create方法将URL作为字符串而不是HTML:

HttpWebRequest r = HttpWebRequest.Create("http://www.google.com");

由于Create上实际上没有HttpWebRequest,而只有WebRequest上,因此您的代码实际上很可能是这样的:

HttpWebRequest r = WebRequest.Create("http://www.google.com");

但是你想要的是这个

HttpWebRequest r = (HttpWebRequest)WebRequest.Create("http://www.google.com");