Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
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", "text/plain")

//  Set the text body of the selected multipart part.
nSuccess := oRest:SetMultipartBodyString("value1")
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

//  Send the multipart request using the configured part(s).
cResponseText := oRest:FullRequestMultipart("POST", "/api/upload")
IF (oRest:LastMethodSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

? cResponseText

oRest:destroy()