C# - 代理检查问题

C# - issue with proxy check

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

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 个代理

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

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

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

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

但是你要的是这个:

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