如何获得一个网址的内容类型? [英] How to get content type of a web address?
本文介绍了如何获得一个网址的内容类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要得到的网页地址的类型。例如这是一个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;
}
这篇关于如何获得一个网址的内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文