Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL lcResponseText

lnSuccess = 0

loRest = CreateObject('Chilkat.Rest')
lnBTls = 1
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("example.com",443,lnBTls,lnBAutoReconnect)
IF (lnSuccess = 0) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

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

*  Send the multipart request using the configured parts.  The response body is returned as text.
lcResponseText = loRest.FullRequestMultipart("POST","/api/upload")
IF (loRest.LastMethodSuccess = 0) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

? lcResponseText

RELEASE loRest