0

我无法检查 url 是否存在。我使用以下方法进行大多数检查 - 这是我找到的最好的方法,可以保存完整的 Web 请求,但它确实允许检查地址,例如:

英国广播公司

m. 的任何移动站点都没有效果和中断。

public static bool Does_URL_Exists(string str_url)
    {
        // using MyClient from linked post
        using (var client = new MyClient())
        {
            client.HeadOnly = true;
            // fine, no content downloaded
            try
            {
                //System.Windows.Forms.MessageBox.Show(str_url);
                string s1 = client.DownloadString(str_url);
                return true;
            }
            catch
            {
                return false;
            }

        }

    }
class MyClient : WebClient
{
    public bool HeadOnly { get; set; }
    protected override WebRequest GetWebRequest(Uri address)
    {
        WebRequest req = base.GetWebRequest(address);
        if (HeadOnly && req.Method == "GET")
        {
            req.Method = "HEAD";
        }
        return req;
    }
}

关于我如何完成这项工作的任何线索。www.bbc.co.uk/m 也不好。

4

1 回答 1

-1

您不需要将所有链接字符串加载到客户端,仅在连接到 url 正常(200)时检查状态。

网址为:“ http://www.bbc.co.uk/ ”。我认为直接链接之类的移动设备是:“ http://www.m.bbc.co.uk/

希望对你有所帮助

于 2013-04-09T21:01:41.967 回答