Sample code for 30+ languages & platforms
PowerBuilder

Set a Multipart Part Body from a StringBuilder

See more REST Examples

Demonstrates Rest.SetMultipartBodySb, which sets the text body of the selected multipart part from a StringBuilder.

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
oleobject loo_SbBody
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

//  Select the multipart part to build, and set its header fields.
loo_Rest.PartSelector = "1"
loo_Rest.AddHeader("Content-Disposition","form-data; name=~"field1~"")
loo_Rest.AddHeader("Content-Type","application/json")

//  Set the text body of the selected part from a StringBuilder.
loo_SbBody = create oleobject
li_rc = loo_SbBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbBody.Append("{ ~"key~": ~"value~" }")
li_Success = loo_Rest.SetMultipartBodySb(loo_SbBody)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbBody
    return
end if

ls_ResponseText = loo_Rest.FullRequestMultipart("POST","/api/upload")
if loo_Rest.LastMethodSuccess = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbBody
    return
end if

Write-Debug ls_ResponseText


destroy loo_Rest
destroy loo_SbBody