How to Find the Size of the HTTP Resource Being Fetched

How to Find the Size of the HTTP Resource Being Fetched

There are cases in which we might want to warn the user before an attempt is made to download a large file, or we might simply be interested to know its size before downloading.

In C#, we use the HttpWebRequest class to download objects from an URL. We can set the request method to be of “Head” type and examine the response header “Content-Length” to determine the size of the object.

string url = "http://mydomain.com/FileStore/bigfile.zip";var urlRequest = (HttpWebRequest)WebRequest.Create(url);//Set the request.method to ???HEAD???urlRequest.Method = "HEAD";var urlResponse = urlRequest.GetResponse();string contentLength = urlResponse.Headers.Get("Content-Length");Messagebox.Show(int.Parse(contentLength).ToString());
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved