Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
string ls_ResponseText

li_Success = 0

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_BTls = 1
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("example.com",443,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

//  Configure a multipart request part before sending.  PartSelector selects the part being built,
//  and the header fields and body apply to that part.
loo_Rest.PartSelector = "1"
loo_Rest.AddHeader("Content-Type","text/plain")
loo_Rest.AddHeader("Content-Disposition","form-data; name=~"field1~"")
li_Success = loo_Rest.SetMultipartBodyString("value1")
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

//  Send the multipart request using the configured parts.  The response body is returned as text.
ls_ResponseText = loo_Rest.FullRequestMultipart("POST","/api/upload")
if loo_Rest.LastMethodSuccess = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

Write-Debug ls_ResponseText


destroy loo_Rest