【问题标题】:Check if Mobile (.m) website exists Query Issue检查移动(.m)网站是否存在查询问题
【发布时间】:2012-11-16 07:12:59
【问题描述】:

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

m.bbc.co.uk

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 也不好。

【问题讨论】:

    标签: c# web httpwebrequest exists


    【解决方案1】:

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

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

    希望对你有所帮助

    【讨论】:

      猜你喜欢
      • 2014-05-05
      • 2013-05-22
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 2011-10-06
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      相关资源
      最近更新 更多