How to get content type of a web address?

前端 未结 5 382
故里飘歌
故里飘歌 2020-12-03 22:21

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

5条回答
  •  情深已故
    2020-12-03 23:05

    it should be something 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;
        }
    

提交回复
热议问题