tags:

views:

52

answers:

2

Using ASP.NET is it possible to make a request and get only response headers? I have to do a request to a big file, but I only need the response headers, i dont care about the content of the file.

I would like to know if there is something similar to get_headers from php (http://php.net/manual/en/function.get-headers.php).

+1  A: 

I'm not sure how to do this natively, but at a minimum, you could use a custom HTTP handler (ASHX) file to create the headers you need, and return nothing else in the response.

Update:

If you set WebRequest.Method = "HEAD" then the server should automatically only return the Headers. This is according to W3.

davisoa
The file is hosted in another server that i dont have control
Cleiton
@davisoa very good. i've made a test using what you suggest and that worked like a charm.
Cleiton
+1  A: 

Yes, see http://stackoverflow.com/questions/1536873/httpwebresponse-closing-the-stream

Hightechrider
wow thanks! that is it!
Cleiton