ContentType detection without full downloading

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
T

Tamir Khason

'm using HttpWebRequest/Response to get content type of urls (a lot of them)
It takes a while, so is it possible to tell to request/response just get a
content type (download only headers) ?

TNX
 
Tamir Khason said:
'm using HttpWebRequest/Response to get content type of urls (a lot of
them)
It takes a while, so is it possible to tell to request/response just get a
content type (download only headers) ?


HTTP defines a 'HEAD' verb for just this purpose. The meaning of the 'HEAD'
verb is basically "Please show me all the headers you would have given me if
I'd done a GET for this URL." So something like this:

HttpWebRequest req = (HttpWebRequest) WebRequest.Create(http://foo/bar);
req.Method = "HEAD";

...


The one caveat is that you sometimes find that HEAD isn't supported. Most
web sites support it, but it's occasionally broken, so you might need to
fall back to a normal GET in failure cases.
 
Back
Top