Sample code for 30+ languages & platforms
AutoIt

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

AutoIt
Local $bSuccess = False

$oRest = ObjCreate("Chilkat.Rest")
Local $bTls = True
Local $bAutoReconnect = True
$bSuccess = $oRest.Connect("example.com",443,$bTls,$bAutoReconnect)
If ($bSuccess = False) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

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

;  Set the text body of the selected part from a StringBuilder.
$oSbBody = ObjCreate("Chilkat.StringBuilder")
$oSbBody.Append("{ ""key"": ""value"" }")
$bSuccess = $oRest.SetMultipartBodySb($oSbBody)
If ($bSuccess = False) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

Local $sResponseText = $oRest.FullRequestMultipart("POST","/api/upload")
If ($oRest.LastMethodSuccess = False) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite($sResponseText & @CRLF)