Sample code for 30+ languages & platforms
PowerShell

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

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$rest = New-Object Chilkat.Rest
$bTls = $true
$bAutoReconnect = $true
$success = $rest.Connect("example.com",443,$bTls,$bAutoReconnect)
if ($success -eq $false) {
    $($rest.LastErrorText)
    exit
}

#  Configure a multipart request part before sending.  PartSelector selects the part being built,
#  and the header fields and body apply to that part.
$rest.PartSelector = "1"
$rest.AddHeader("Content-Type","text/plain")
$rest.AddHeader("Content-Disposition","form-data; name=`"field1`"")
$success = $rest.SetMultipartBodyString("value1")
if ($success -eq $false) {
    $($rest.LastErrorText)
    exit
}

#  Send the multipart request using the configured parts.  The response body is returned as text.
$responseText = $rest.FullRequestMultipart("POST","/api/upload")
if ($rest.LastMethodSuccess -eq $false) {
    $($rest.LastErrorText)
    exit
}

$($responseText)