Re: HHTP file download:
From: Scott Fant (scottfant_at_nospam.peoplepc.com)
Date: 02/22/04
- Next message: Darren Clark: "Re: Dynamic loading and debugging"
- Previous message: David G: "Re: VS .Net 2004 Whidbey"
- In reply to: Bryan Martin: "Re: HHTP file download:"
- Next in thread: Frank Rizzo: "Re: HHTP file download:"
- Messages sorted by: [ date ] [ thread ]
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
> >
> >
>
>
- Next message: Darren Clark: "Re: Dynamic loading and debugging"
- Previous message: David G: "Re: VS .Net 2004 Whidbey"
- In reply to: Bryan Martin: "Re: HHTP file download:"
- Next in thread: Frank Rizzo: "Re: HHTP file download:"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|