postmanlabs / postmanlabs/postman-code-generators

PowerShell - RestMethod Code snippet doesn’t work

Open
#763 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1k
Forks
381
PR merge metrics
No merged PRs in 30d

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the PowerShell Invoke-RestMethod code generator and reproduce the multipart/form-data example from the issue. Compare the generated request with the Fiddler result, focusing on the missing Content-Type boundary and the body rendered as System.Net.Http.StringContent; done when the generated snippet sends the multipart fields correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, powershell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.