Sample code for 30+ languages & platforms
Xbase++

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 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

//  Configure a multipart request part before sending.  PartSelector selects the part being built,
//  and the header fields and body apply to that part.
oRest:PartSelector := "1"
oRest:AddHeader("Content-Type", "text/plain")
oRest:AddHeader("Content-Disposition", 'form-data; name="field1"')
nSuccess := oRest:SetMultipartBodyString("value1")
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

//  Send the multipart request using the configured parts.  The response body is returned as text.
cResponseText := oRest:FullRequestMultipart("POST", "/api/upload")
IF (oRest:LastMethodSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

? cResponseText

oRest:destroy()