PureBasic
PureBasic
QuickGetBd Example
The QuickGetBd method is called to send a GET request to download a binary target, such as PDF, zip, image file, etc. into a Chilkat BinData object.Chilkat PureBasic Downloads
IncludeFile "CkBinData.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkPdf.pb"
Procedure ChilkatExample()
success.i = 0
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttp::setCkKeepResponseBody(http, 1)
bd.i = CkBinData::ckCreate()
If bd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Download the contents of a PDF file into the bd object.
success = CkHttp::ckQuickGetBd(http,"https://www.chilkatsoft.com/hello.pdf",bd)
If success = 0
; This will happen if the response status code was 400 or greater,
; or if the request could not be sent, or if no response was received.
;
; In other words, success will only be 1 if bd contains the desired content at the URL (not an error response).
statusCode.i = CkHttp::ckLastStatus(http)
Debug "Response status: " + Str(statusCode)
If statusCode = 0
; There was an error in communications.
Debug CkHttp::ckLastErrorText(http)
Else
; We received a response status code indicating failure.
; Examine the response body.
Debug CkHttp::ckLastResponseBody(http)
EndIf
CkHttp::ckDispose(http)
CkBinData::ckDispose(bd)
ProcedureReturn
EndIf
; Load the downloaded PDF into a Chilkat PDF object.
pdf.i = CkPdf::ckCreate()
If pdf.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkPdf::ckLoadBd(pdf,bd)
If success = 0
Debug CkPdf::ckLastErrorText(pdf)
CkHttp::ckDispose(http)
CkBinData::ckDispose(bd)
CkPdf::ckDispose(pdf)
ProcedureReturn
EndIf
; ...
Debug "Success."
CkHttp::ckDispose(http)
CkBinData::ckDispose(bd)
CkPdf::ckDispose(pdf)
ProcedureReturn
EndProcedure