DataFlex
DataFlex
Example: Http.HttpFile method
Shows how to use the HttpFile method to send an HTTP POST request with the contents of a file as the request body. The example sends the following request:POST /api/v1/sites/123/deploys HTTP/1.1 Host: example.com Accept: */* Accept-Encoding: gzip Content-Type: application/zip Content-Length: 123456 [binary data bytes of data.zip]
Also see: Chilkat Http Default and Auto-Filled Headers
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
String sLocalFilePath
String sUrl
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Move "C:/example/zips/data.zip" To sLocalFilePath
Move "https://example.com/api/v1/sites/123/deploys" To sUrl
// Send a POST with the contents of the file in the binary HTTP request body.
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoResp to vResp
Get ComHttpFile Of hoHttp "POST" sUrl sLocalFilePath "application/zip" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln "Response Status Code: " iTemp1
Showln "Response body:"
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
End_Procedure