如何获得一个网址的内容类型?如何获得、类型、网址、内容

2023-09-04 11:18:24 作者:◣倔強的夢想◢

我想要得到的网页地址的类型。例如这是一个HTML页面,它的页面类型是的text / html 但这的类型是文/ XML 。 此页的类型似乎是图像/ PNG 但它的的text / html

I want to get type of a web address. For example this is a Html page and its page type is text/html but the type of this is text/xml. this page's type seems to be image/png but it's text/html.

我想知道我怎么可以检测的是Web地址的内容类型一样的这?

I want to know how can I detect the content type of a web address like this?

推荐答案

应该是这样的。

    var request = HttpWebRequest.Create("http://www.google.com") as HttpWebRequest;
    if (request != null)
    {
        var response = request.GetResponse() as HttpWebResponse;

        string contentType = "";

        if (response != null)
            contentType = response.ContentType;
    }