|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
WebRequest: only get info about file, not download the file?i want to get the file size of some files located on a webserver, therefore i create a WebRequest with the URI of the file and then a WebResponse on the WebRequest to get the ContentLength: WebRequest webRequest = HttpWebRequest.Create(fileUri); webRequest.Method = "HEAD"; //??????? (*) WebResponse webResponse = webRequest.GetResponse(); fileSizeBytes = (ulong)webResponse.ContentLength; (*) Does this setting make the WebRequest only send the info and not the complete file? I ask because i don't want to download large files completely only to get the filename. Thank you very much in advance, Roland Thus wrote Roland,
> Hello Group, WebRequest is a, um, request ;-)> > i want to get the file size of some files located on a webserver, > therefore i create a WebRequest with the URI of the file and then a > WebResponse on the WebRequest to get the ContentLength: > > WebRequest webRequest = HttpWebRequest.Create(fileUri); > webRequest.Method = "HEAD"; //??????? (*) > WebResponse webResponse = webRequest.GetResponse(); > fileSizeBytes = (ulong)webResponse.ContentLength; > (*) Does this setting make the WebRequest only send the info and not > the complete file? The file will be part of the response. > A HEAD request is similar to a GET request, but the server will not send > I ask because i don't want to download large files completely only to > get the filename. a HTTP body, only the headers. If these headers contain Content-Length, you'll get what you need. Cheers, -- Joerg Jooss news-re***@joergjooss.de Thanks Joerg, i did analyze it with a network trace tool and it does
exactly what i want. Joerg Jooss schrieb: Show quote > Thus wrote Roland, > >> Hello Group, >> >> i want to get the file size of some files located on a webserver, >> therefore i create a WebRequest with the URI of the file and then a >> WebResponse on the WebRequest to get the ContentLength: >> >> WebRequest webRequest = HttpWebRequest.Create(fileUri); >> webRequest.Method = "HEAD"; //??????? (*) >> WebResponse webResponse = webRequest.GetResponse(); >> fileSizeBytes = (ulong)webResponse.ContentLength; >> (*) Does this setting make the WebRequest only send the info and not >> the complete file? > > WebRequest is a, um, request ;-) > The file will be part of the response. > >> >> I ask because i don't want to download large files completely only to >> get the filename. > > A HEAD request is similar to a GET request, but the server will not send > a HTTP body, only the headers. If these headers contain Content-Length, > you'll get what you need. > > Cheers, |
|||||||||||||||||||||||