DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vBd
Handle hoBd
Integer iStatusCode
Handle hoPdf
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComKeepResponseBody Of hoHttp To True
Get Create (RefClass(cComChilkatBinData)) To hoBd
If (Not(IsComObjectCreated(hoBd))) Begin
Send CreateComObject of hoBd
End
// Download the contents of a PDF file into the bd object.
Get pvComObject of hoBd to vBd
Get ComQuickGetBd Of hoHttp "https://www.chilkatsoft.com/hello.pdf" vBd To iSuccess
If (iSuccess = False) Begin
// 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 True if bd contains the desired content at the URL (not an error response).
Get ComLastStatus Of hoHttp To iStatusCode
Showln "Response status: " iStatusCode
If (iStatusCode = 0) Begin
// There was an error in communications.
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
End
Else Begin
// We received a response status code indicating failure.
// Examine the response body.
Get ComLastResponseBody Of hoHttp To sTemp1
Showln sTemp1
End
Procedure_Return
End
// Load the downloaded PDF into a Chilkat PDF object.
Get Create (RefClass(cComChilkatPdf)) To hoPdf
If (Not(IsComObjectCreated(hoPdf))) Begin
Send CreateComObject of hoPdf
End
Get pvComObject of hoBd to vBd
Get ComLoadBd Of hoPdf vBd To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
// ...
Showln "Success."
End_Procedure