如何获取网址的内容类型? [英] How to get content type of a web address?
本文介绍了如何获取网址的内容类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取网址类型.例如 this 是一个 Html 页面,它的页面类型是 text/html
但是这个的类型是text/xml
.this 页面的类型似乎是 image/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
.
我想知道如何检测诸如 这个?
推荐答案
应该是这样的
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屋!
查看全文