3

I'm working on a YouTube Downloader, which gets sizes of all qualities available but usually that takes a very long time and sometimes it just goes like a lightning !

I wrote this Function and it's pretty good [ only sometimes as I said before ] !

    Uri url = new Uri("http://example.com/document.docx");
    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    response.Close();

    // iSize will handle the size of the file in bytes
    Int64 iSize = response.ContentLength;

.

So, Is there a faster way to do this ? ( Put on your mind that the files which will be measured are more than eight files ) .

.

In advance, thank you so much ;

Alaa Alrifaie
  • 49
  • 1
  • 5

1 Answers1

1

That completely depends on how well-behaved the HTTP server is.

The specification says that you can send a HEAD request to get response headers like Content-Length without serving the file.

However, many servers don't do that.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964