c# get content-type of url
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; }
using (MyClient client = new MyClient()) { client.HeadOnly = true; string uri = "http://www.google.com"; byte[] body = client.DownloadData(uri); // note should be 0-length string type = client.ResponseHeaders["content-type"]; client.HeadOnly = false; // check 'tis not binary... we'll use text/, but could // check for text/html if (type.StartsWith(@"text/")) { string text = client.DownloadString(uri); Console.WriteLine(text); } }









