DataFlex
DataFlex
Send a Multipart REST Request
See more REST Examples
Demonstrates Rest.FullRequestMultipart, which sends a complete multipart request using the parts configured on the object, then returns the response body as text.
Background. Each multipart part is built by selecting it with the part selector, adding its header fields, and setting its body. FullRequestMultipart then assembles and sends all configured parts as a single multipart request.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Boolean iBAutoReconnect
String sResponseText
String sTemp1
Boolean bTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Move True To iBTls
Move True To iBAutoReconnect
Get ComConnect Of hoRest "example.com" 443 iBTls iBAutoReconnect To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Configure a multipart request part before sending. PartSelector selects the part being built,
// and the header fields and body apply to that part.
Set ComPartSelector Of hoRest To "1"
Get ComAddHeader Of hoRest "Content-Type" "text/plain" To iSuccess
Get ComAddHeader Of hoRest "Content-Disposition" 'form-data; name="field1"' To iSuccess
Get ComSetMultipartBodyString Of hoRest "value1" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Send the multipart request using the configured parts. The response body is returned as text.
Get ComFullRequestMultipart Of hoRest "POST" "/api/upload" To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Showln sResponseText
End_Procedure