Xbase++
Xbase++
Set a Multipart Part Body from a StringBuilder
See more REST Examples
Demonstrates Rest.SetMultipartBodySb, which sets the text body of the selected multipart part from a StringBuilder.
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL oSbBody
LOCAL cResponseText
nSuccess := 0
oRest := CreateObject("Chilkat.Rest")
nBTls := 1
nBAutoReconnect := 1
nSuccess := oRest:Connect("example.com", 443, nBTls, nBAutoReconnect)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// Select the multipart part to build, and set its header fields.
oRest:PartSelector := "1"
oRest:AddHeader("Content-Disposition", 'form-data; name="field1"')
oRest:AddHeader("Content-Type", "application/json")
// Set the text body of the selected part from a StringBuilder.
oSbBody := CreateObject("Chilkat.StringBuilder")
oSbBody:Append('{ "key": "value" }')
nSuccess := oRest:SetMultipartBodySb(oSbBody)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oSbBody:destroy()
RETURN
ENDIF
cResponseText := oRest:FullRequestMultipart("POST", "/api/upload")
IF (oRest:LastMethodSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oSbBody:destroy()
RETURN
ENDIF
? cResponseText
oRest:destroy()
oSbBody:destroy()