Re: HHTP file download:

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Scott Fant (scottfant_at_nospam.peoplepc.com)
Date: 02/22/04


Date: Sun, 22 Feb 2004 15:09:15 -0600

Well, I've never done this with VB.NET, but in using C++ and windows sockets
I simply sent a HEAD request to the server to get the content length before
requesting the file with the GET method.

Here is some information from the HTTP RFC concerning content length and
what to do if a content length header is not returned....

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

14.13 Content-Length
The Content-Length entity-header field indicates the size of the
entity-body, in decimal number of OCTETs, sent to the recipient or, in the
case of the HEAD method, the size of the entity-body that would have been
sent had the request been a GET.

       Content-Length = "Content-Length" ":" 1*DIGIT
An example is

       Content-Length: 3495
Applications SHOULD use this field to indicate the transfer-length of the
message-body, unless this is prohibited by the rules in section 4.4.

Any Content-Length greater than or equal to zero is a valid value. Section
4.4 describes how to determine the length of a message-body if a
Content-Length is not given.

Note that the meaning of this field is significantly different from the
corresponding definition in MIME, where it is an optional field used within
the "message/external-body" content-type. In HTTP, it SHOULD be sent
whenever the message's length can be determined prior to being transferred,
unless this is prohibited by the rules in section 4.4.

Here's a link to section 4.4 that's mentioned....

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4

"Bryan Martin" <uce@ftc.gov> wrote in message
news:emEl52X%23DHA.2664@TK2MSFTNGP09.phx.gbl...
> Cor, thanks again for the response however you have missed the question
> again. I know you can get the content length from the headers, matter of
> fact there is a much easier way to do it than the example you gave.
Problem
> is not all servers send a content length so I would like to know how for
> instance internet explorer's download dialog knows the file size so it can
> give you a idea of how long its gonna take you to download the file.
Again
> as stated I have downloaded files from a server I know is not giving a
> content length and internet explorer's dialog box still correctly displays
> the time/progress while downloading.
>
> BTW the httpwebresponse has a "contentlength" method which will return the
> value without having to loop through all headers.
>
> Bryan
>
> Dim str_Site As String = "http://download.winzip.com/winzip81.exe"
> Dim obj_HTTPWebRequest As System.Net.HttpWebRequest =
> System.Net.HttpWebRequest.Create(str_Site)
> Dim obj_HTTPWebResponse As System.Net.HttpWebResponse =
> obj_HTTPWebRequest.GetResponse
> Debug.WriteLine(obj_HTTPWebResponse.ContentLength)
>
>
> "Cor" <non@non.com> wrote in message
> news:OUQ6WpW%23DHA.1424@TK2MSFTNGP12.phx.gbl...
> > Hi Bryan,
> >
> > I am not completly sure of it, but I have distributed this before (I
have
> > this in a program, but I had to delete a lot to make it only for what
you
> > ask)..
> >
> > \\\not tested as is
> > dim conlength as string
> > Dim wbRq As HttpWebRequest = DirectCast(WebRequest.Create(item.Text),
> > HttpWebRequest)
> > wbRq.Timeout = 2000
> > Try
> > Dim wbRs As HttpWebResponse = DirectCast(wbRq.GetResponse(),
> > HttpWebResponse)
> > Dim wbHCol As WebHeaderCollection = wbRs.Headers
> > For i As Integer = 0 To wbHCol.Count - 1
> > Dim header As String = wbHCol.GetKey(i)
> > Dim values As String() = wbHCol.GetValues(header)
> > If values.Length > 0 andalso header.Tolower = "content-lenght"
> Then
> > conlenght = values(0)
> > End If
> > Next
> > wbRs.Close()
> > Catch
> > conlength = "?"
> > End Try
> > ///
> > I hope this helps a little bit?
> >
> > Cor
> >
> >
>
>



Relevant Pages

  • Re: File Download
    ... One method you could use is to create as Web Service on the server hosting ... Using SAOP you can then connect to your file server and request the file. ... > I have a web application that allows users to download files. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: HHTP file download:
    ... I simply sent a HEAD request to the server to get the content length before ... > give you a idea of how long its gonna take you to download the file. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: downloading a single file using multiple threads
    ... One client A --- one Server, ... thread 1 issues asynchronous range request x... ... isn't useful (as you say, even if you have enabled reuse of the connection, repeated requests for different ranges will simply result in queuing of the replies). ... Yep, but say you have 1Mbps to the US and 50Kbps to Afrika, is your download manager clever enough to request all chunks from the US instead of waiting for a chunk to arrive from Afrika, or is he clever enough to cancel the request and re-issue the same request over the US connection. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: URL Connection & Files
    ... > having to download the file? ... If the HTTP HEAD request doesn't work then ... HTTP HEAD, and is less likely to be supported. ... The server must expose ...
    (comp.lang.java.programmer)
  • Re: URL Connection & Files
    ... > having to download the file? ... If the HTTP HEAD request doesn't work then ... HTTP HEAD, and is less likely to be supported. ... The server must expose ...
    (comp.lang.java.help)