0

I had to send a POST request to a Cloud Platform including a zipped csv file. At the moment I´m using Postman for this, and it goes all correctly. On the Webserver it is not possible to install Postman, so I have to use Powershell for this. I have a problem to find out how the body is to insert in the script:

The Correct Postman post - on the "Code snippet" - with CURL Postman says i have to make it like this:

curl --location --request POST 'https://api.../v..../xxx.csv' \
--header 'Content-Type: application/octet-stream' \
--header 'Ocp-Apim-Subscription-Key: xxxxxx' \
--data-binary '....../brunico.zip'**

on Postman the Code snippet for Powershell ist not fully described, for the body is written: ...file contents here...

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/octet-stream")
$headers.Add("Ocp-Apim-Subscription-Key", "xxxxxx")

$body = "<file-contents-here>"***

$response = Invoke-RestMethod 'https://api.../v..../xxx.csv' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json**

how do I insert the zip file in the body?

  • Did you try the `-InFile` parameter? See the [official documentation](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.2) for details. Also, here is a similar question that might help: [How to use Invoke-RestMethod to upload jpg](https://stackoverflow.com/questions/42395638/how-to-use-invoke-restmethod-to-upload-jpg) – boxdog May 06 '22 at 09:12
  • Perfectly! $body = "filepath" and in the Invoke-RestMethod: instead of ....-body $body...... using .....-Infile $body.... resolved the problem! – Stefan Stürz May 06 '22 at 10:10

0 Answers0