Skip to content

PowerShell - RestMethod Code snippet doesn’t work #763

Open
@sergey-ka

Description

@sergey-ka

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions