DataFlex
DataFlex
Set a Multipart Part Body from a String
See more REST Examples
Demonstrates Rest.SetMultipartBodyString, which sets the text body of the currently selected multipart part.
Background. A multipart request is assembled part by part: the part selector chooses the part being built, header fields describe it, and a SetMultipartBody method supplies its content. The request is then sent with a multipart send or full-request method.
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
// Select the multipart part to build, and set its header fields.
Set ComPartSelector Of hoRest To "1"
Get ComAddHeader Of hoRest "Content-Disposition" 'form-data; name="field1"' To iSuccess
Get ComAddHeader Of hoRest "Content-Type" "text/plain" To iSuccess
// Set the text body of the selected multipart part.
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 part(s).
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