PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkRest.pb"
Procedure ChilkatExample()
success.i = 0
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
bTls.i = 1
bAutoReconnect.i = 1
success = CkRest::ckConnect(rest,"example.com",443,bTls,bAutoReconnect)
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
; Configure a multipart request part before sending. PartSelector selects the part being built,
; and the header fields and body apply to that part.
CkRest::setCkPartSelector(rest, "1")
CkRest::ckAddHeader(rest,"Content-Type","text/plain")
CkRest::ckAddHeader(rest,"Content-Disposition","form-data; name=" + Chr(34) + "field1" + Chr(34))
success = CkRest::ckSetMultipartBodyString(rest,"value1")
If success = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
; Send the multipart request using the configured parts. The response body is returned as text.
responseText.s = CkRest::ckFullRequestMultipart(rest,"POST","/api/upload")
If CkRest::ckLastMethodSuccess(rest) = 0
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
Debug responseText
CkRest::ckDispose(rest)
ProcedureReturn
EndProcedure