.net httpwebrequest determine mime type before downloading

Hi all,

I am downloading some web pages with httpwebrequest. I only want to download the file if it is indeed an html file, and not if it's a binary file. Is there a way to check the MIME type before downloading?
zattzAsked:
Who is Participating?
 
DarkoLordConnect With a Mentor Commented:
You can check the HttpWebResponse.ContentType property just after you get the response:

HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create("http://www.something.com");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.ContentType.ToLower() == "text/html")
{
   // get the stream
   Stream resStream = response.GetResponseStream();
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.