[Gambas-user] Problem retreiving Headers with HttpClient
Laurent Carlier
lordheavym at ...626...
Wed Jul 11 00:13:20 CEST 2007
On Tuesday 10 July 2007 22:59:29 Laurent Carlier wrote:
> I'm delepping some kind of file downloader and i need to retreive the
> header of the file i try to download if i want to guess the size of the
> file (currently tagged with 'Content - Length:')
>
> Unfortunatly i don't succeed :-/, the header i retreive is empty or
> garbaged. I don't know if i've made a mistake or if it's a bug. The same
> url give a correct header with hhtpget example.
>
> The code :
> PUBLIC _Download AS NEW HttpClient AS "_Download"
>
> PRIVATE downloadBuffer AS String
> PRIVATE sTempFile AS String
>
> ' Destination file
> PRIVATE sDestFile AS String
> PRIVATE oDestFile AS Stream
> PRIVATE iDestFileSize AS Integer
> PRIVATE iDestFileCurrentSize AS Integer
>
> PUBLIC SUB run(URL AS String)
>
> downloadBuffer = ""
>
> WITH _Download
> .URL = URL
> .UserAgent = "Gambas Http/1.0"
> .Get()
> END WITH
>
> END
>
> PUBLIC SUB _Download_Connect()
>
> PRINT "Connection found " & _download.URL
> SLEEP 2
> END
>
> PUBLIC SUB _Download_Read()
>
> DIM buffer AS String
> DIM size AS Integer
> DIM myLoop AS Integer
>
> size = iDestFileSize
>
> ' Check for the size of the downloaded file
> IF (size = 0)
> FOR myLoop = 0 TO _Download.Headers.Count - 1
> IF (InStr(_Download.Headers[MyLoop], "Content - Length:") > 0) THEN
> PRINT "length found"
> NEXT
> ENDIF
>
> IF Lof(LAST)
> iDestFileCurrentSize = iDestFileCurrentSize + Lof(LAST)
> IF (size = 0) THEN size = iDestFileCurrentSize
> READ #LAST, buffer, Lof(LAST)
> downloadBuffer &= buffer
> PRINT iDestFileCurrentSize & " Downnload on " & size
> ENDIF
>
> END
>
> PUBLIC SUB _Download_Error()
>
> PRINT "Error " & _download.Status & " downloading " & _download.URL
>
> END
>
> PUBLIC SUB _Download_Finished()
>
> FOR myLoop = 0 TO _Download.Headers.Count - 1
> PRINT _Download.Headers[MyLoop]
> NEXT
>
> PRINT "finished"
>
> END
>
>
> Regards,
Ok, i've found an error (no spaces in Context-Length: string :-/
But there is still an error : unable to print the strings in the console, the
string is correctly printed in debugging mode.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20070711/b0aff865/attachment.sig>
More information about the User
mailing list