<p>I want to get the size of an http:/.../file before I download it. The file can be a webpage, image, or a media file. Can this be done with HTTP headers? How do I download just the file HTTP header?</p>

Can this be done with HTTP headers?
Yes, this is the way to go.
If
the information is provided, it's in the header as the
```
Content-Length
```
. Note, however, that this is not necessarily the case.
Downloading only the header can be done using a
```
HEAD
```
request instead of
```
GET
```
. Maybe the following code helps:
```
```
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://example.com/");
req.Method = "HEAD";
long len;
using(HttpWebResponse resp = (HttpWebResponse)(req.GetResponse()))
{
    len = resp.ContentLength;
}
```
```
Notice the property for the content length on the
```
HttpWebResponse
```
object – no need to parse the
```
Content-Length
```
header manually.