[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

.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?
1 Solution
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();

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now