More Properties in cHttpTransfer
<< Back
The cHttpTransfer is just
a wrapper for Win32 WinINet. The wrapper itself is far
from comprehensive, but it does capture some of the most important features within WinINet. If you want more out of your cHttpTransfer class, you
can dig deeper into the WinINet APIs for more. In this article, we are going to look into three properties that are not in the current cHttpTransfer class.
- INTERNET_OPTION_CONTROL_SEND_TIMEOUT - Timeout for sending data
- INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT - Timeout for receiving data
- INTERNET_OPTION_HTTP_DECODING - Whether to decompress GZip/Deflate encoding schemes automatically if the incoming data is compressed/encoded
Use cHttpTransfer.pkg
External_Function InternetSetOption "InternetSetOptionA" WININET.DLL Handle hInternet DWord dwOption Pointer lpBuffer DWord dwBufferLength Returns Boolean
Define INTERNET_OPTION_CONTROL_SEND_TIMEOUT For 5
Define INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT For 6
Define INTERNET_OPTION_HTTP_DECODING For 65
Class cHttpTransferEx is a cHttpTransfer
Procedure Set TimeOut Integer iTimeOut // in milliseconds
Handle hInternet
Integer iSize
Boolean bOK
Get RootHandle to hInternet
Move (SizeOfType(Integer)) to iSize
Move (InternetSetOption (hInternet, INTERNET_OPTION_CONTROL_SEND_TIMEOUT, AddressOf(iTimeOut), iSize)) to bOk
Move (InternetSetOption (hInternet, INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, AddressOf(iTimeOut), iSize)) to bOk
End_Procedure // TimeOut
Procedure Set EnableGZipDecompression Boolean bEnable
Handle hInternet
Integer iEnable
Boolean bOK
Get RootHandle to hInternet
Move bEnable to iEnable
Move (InternetSetOption (hInternet, INTERNET_OPTION_HTTP_DECODING, AddressOf(iEnable), SizeOfType(Integer))) to bOk
End_Procedure
Procedure OnDataReceived string sContentType string sData // This is for testing purpose
Forward Send OnDataReceived sContentType sData
Showln sData
End_Procedure
End_Class
Here is to test it out
Procedure Test
Handle hHttp
Handle iResult
Get Create (RefClass(cHttpTransferEx)) to hHttp
Set piRemotePort of hHttp to rpHttpSSL
Set peTransferFlags of hHttp to ifSecure
Set psRemoteHost of hHttp to "yahoo.com"
Set EnableGZipDecompression of hHttp to True // Try commenting it out to see what happens
Get AddHeader of hHttp "Accept-Encoding" "gzip, deflate, br" to iResult
Get HttpGetRequest of hHttp "/" to iResult
InKey FieldIndex
End_Procedure
Send Test