Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell - RestMethod Code snippet doesn’t work #763

Open
sergey-ka opened this issue Aug 22, 2024 · 0 comments
Open

PowerShell - RestMethod Code snippet doesn’t work #763

sergey-ka opened this issue Aug 22, 2024 · 0 comments

Comments

@sergey-ka
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant