Code: Select all
;* DESC
;* Download a file from Internet using the HTTP protocol.
;*
;* IN
;* *tHTTP ; See the description on the T_PBL_HTTP_GET_FROM_WEB structure for the usage of the input / output fields.
;*
;* OUT
;* *tHTTP ; See the description on the T_PBL_HTTP_GET_FROM_WEB structure for the usage of the input / output fields.
;*
;* RET
;* #WEB_OK ; If successful.
;* #WEB_ERR_INVALID_PARAMETERS ; If parameters are missing or invalid.
;* #WEB_ERR_OUT_OF_MEMORY ; If there is an error WHILE allocating memory for the data buffers.
;* #WEB_ERR_FILE_CREATION ; If there is an error while creating the file on the disk.
;* #WEB_ERR_FILE_IO ; If there is an error while writing the file to the disk.
;* #WEB_ERR_USER_ABORT ; If the callback return #False the download has been aborted by request.
;* #WEB_ERR_HTTP_STATUS ; If different from HTTP OK (200), the actual value will be returned in *tHTTP\iErrorCodeEx.
;* #WEB_ERR_HTTP_OPEN ; Error in the API call to open.
;* #WEB_ERR_HTTP_CONNECT ; Error in the API call to connect.
;* #WEB_ERR_HTTP_SET_PROXY ; Error in the API call to set proxy.
;* #WEB_ERR_HTTP_BASIC_AUTH ; Error in the API call to basic auth.
;* #WEB_ERR_HTTP_HTTP_OPEN ; Error in the API call to HTTP open.
;* #WEB_ERR_HTTP_HTTP_SEND ; Error in the API call to HTTP send.
;* #WEB_ERR_HTTP_HTTP_QUERY_STATUS ; Error in the API call to query status.
;* #WEB_ERR_HTTP_READ ; Error in the API call to read.
;* #WEB_ERR_HTTP_CLOSE ; Error in the API call to close.
;*
;* EXAMPLE
;* See the sample programs HTTPGetFromWeb_1.pb, HTTPGetFromWeb_2.pb.
;*
;* The simplest form: download bar.zip in memory.
;* The pointer to the allocated memory area will be returned in tHTTP\*DestBuffer.
;*
;* tHTTP\iThreadID = 0
;* tHTTP\URL$ = "http://www.somedomain.com/foo/bar.zip"
;* tHTTP\iDestination = #WEB_WRITE_TO_MEMORY
;* HTTPGetFromWeb (@tHTTP)
;*
;* Same as above, loaded entirely in memory and then copied to the specified file.
;* The memory in this case will be automatically freed by the procedure after
;* saving the file to disk.
;*
;* tHTTP\iThreadID = 0
;* tHTTP\URL$ = "http://www.somedomain.com/foo/bar.zip"
;* tHTTP\iDestination = #WEB_WRITE_TO_FILE
;* tHTTP\FullFileName$ = "c:\download\bar.zip"
;* HTTPGetFromWeb (@tHTTP)
;*
;* Again we download bar.zip, but this time we don't load it entirely in memory.
;* We try to load it in "chunks" of 16384 bytes, the proc will automatically save a chunk to
;* file and then repeat the process until the download is completed.
;* In this call we use a callback procedure as well.
;* The callback procedure (see the prototype definition) will receive
;* - a pointer to the tHTTP structure
;* - the number of bytes downloaded up to this point
;* - the total size of the download (if available, else 0)
;* - the time passed in seconds from the start of the download.
;*
;* tHTTP\iThreadID = 0
;* tHTTP\URL$ = "http://www.somedomain.com/foo/bar.zip"
;* tHTTP\iDestination = #WEB_WRITE_TO_FILE
;* tHTTP\FullFileName$ = "c:\download\bar.zip"
;* tHTTP\iChunkSize = 16384
;* tHTTP\fpCB_Working = @MyCallBack()
;* HTTPGetFromWeb (@tHTTP)
;*
;* Same as above but using a proxy without authentication required.
;*
;* tHTTP\iThreadID = 0
;* tHTTP\URL$ = "http://www.somedomain.com/foo/bar.zip"
;* tHTTP\iAccess = #INTERNET_OPEN_TYPE_PROXY
;* tHTTP\ProxyAndPort$ = "192.168.1.1:8080"
;* tHTTP\iDestination = #WEB_WRITE_TO_FILE
;* tHTTP\FullFileName$ = "c:\download\bar.zip"
;* tHTTP\iChunkSize = 16384
;* tHTTP\fpCB_Working = @MyCallBack()
;* HTTPGetFromWeb (@tHTTP)
;*
;* Same as above but using a proxy requiring authentication,
;*
;* tHTTP\iThreadID = 0
;* tHTTP\URL$ = "http://www.somedomain.com/foo/bar.zip"
;* tHTTP\iAccess = #INTERNET_OPEN_TYPE_PROXY
;* tHTTP\ProxyAndPort$ = "192.168.1.1:8080"
;* tHTTP\ProxyUsername$ = "username"
;* tHTTP\ProxyPassword$ = "password"
;* tHTTP\iDestination = #WEB_WRITE_TO_FILE
;* tHTTP\FullFileName$ = "c:\download\bar.zip"
;* tHTTP\iChunkSize = 16384
;* tHTTP\fpCB_Working = @MyCallBack()
;* HTTPGetFromWeb (@tHTTP)
;*
;* Accessing an HTTP resource requiring basic authentication
;*
;* tHTTP\iThreadID = 0
;* tHTTP\URL$ = "http://username:password@www.somedomain.com/foo/bar.zip"
;* tHTTP\iDestination = #WEB_WRITE_TO_FILE
;* tHTTP\FullFileName$ = "c:\download\bar.zip"
;* tHTTP\iChunkSize = 16384
;* tHTTP\fpCB_Working = @MyCallBack();
;* HTTPGetFromWeb (@tHTTP)
;*
;* Accessing an HTTP resource requiring basic authentication through a
;* proxy requiring authentication
;*
;* tHTTP\iThreadID = 0
;* tHTTP\URL$ = "http://username:password@www.somedomain.com/foo/bar.zip"
;* tHTTP\iAccess = #INTERNET_OPEN_TYPE_PROXY
;* tHTTP\ProxyAndPort$ = "192.168.1.1:8080"
;* tHTTP\ProxyUsername$ = "username"
;* tHTTP\ProxyPassword$ = "password"
;* tHTTP\iDestination = #WEB_WRITE_TO_FILE
;* tHTTP\FullFileName$ = "c:\download\bar.zip"
;* tHTTP\iChunkSize = 16384
;* tHTTP\fpCB_Working = @MyCallBack()
;* HTTPGetFromWeb (@tHTTP)
;*
;* NOTES
;* The procedure will fall back to use the chunk method even if "all in one block" is requested if the server doesn't return the
;* total size of the file we are about to download.
;* This happen for example when downloading stock quotes from the Yahoo site.
;*
;* The main callback procedure can optionally abort a download (if in chunk mode) when a user defined custom condition arise,
;* returning #False instead of #True.
;*
;* Valid values for *tHTTP\iAccess
;*
;* #INTERNET_OPEN_TYPE_DIRECT ; Try a direct connection to the Internet.
;* #INTERNET_OPEN_TYPE_PROXY ; Try to passes the requests to the proxy specified in ProxyAndPort$.
;*
;* Valid values for *tHTTP\iFlags
;*
;* #INTERNET_FLAG_NO_UI ; Disables the cookie dialog box if cookies received.
;*
;* #INTERNET_FLAG_RELOAD ; Forces a download of the requested file from the server, not from the cache.
;*
;* #INTERNET_FLAG_NO_COOKIES ; Does not automatically add cookie headers to requests, and does not automatically add
;* ; returned cookies to the cookie database.
;*
;* #INTERNET_FLAG_NO_AUTO_REDIRECT ; Does not automatically handle redirection in HttpSendRequest.
Download [... from someone who got a copy at the time].