-
Notifications
You must be signed in to change notification settings - Fork 376
PowerShell - RestMethod Code snippet doesn’t work #763
Copy link
Copy link
Open
Description
I use PowerShell - RestMethod Code Snippet to get PoserShell code.
But it doesn’t work.
Below is what concerns me:
- The code doesn’t include Content-Type to the header if it’s set "boundary=calculated when request is sent"
- The suggested code to create “multipart/form-data” is
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("authtoken", "bclzcBL3i2C0ccaWrb3EDLVSigwpWnrObDekm0+fxAM=")
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new(“form-data”)
$stringHeader.Name = “solutionName”
$stringContent = [System.Net.Http.StringContent]::new(“SK”)
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "planName"
$stringContent = [System.Net.Http.StringContent]::new("Test plan")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)
$body = $multipartContent
$response = Invoke-RestMethod 'http://server.com/services/v1/plan' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
but I don’t see correct body in Fiddler, just the below string
System.Net.Http.StringContent
Thanks
Postman for Windows
Version
11.8.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.