Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP PUT a file in Powershell and capture response body?

I'd like to upload a file using PowerShell and capture the resulting response body. How can one do this?

I've tried:

$env:DEPLOY_URL = & curl.exe https://make.mudlet.org/snapshots/Mudlet-$env:VERSION$env:MUDLET_VERSION_BUILD-windows.zip --upload-file Mudlet-$env:VERSION$env:MUDLET_VERSION_BUILD-windows.zip 2>&1

But that does not work and says Command executed with exception: without listing the exception.

like image 755
Vadim Peretokin Avatar asked Dec 01 '25 01:12

Vadim Peretokin


1 Answers

Explore using the Invoke-RestMethod command. You can save the response body using the -OutFile parameter.

An example PUT would be as follows where $uri is the destination, $inFile is the path to the local file, and $outFile is the path to where to save the response body:

Invoke-RestMethod -Uri $uri -Method PUT -InFile $inFile -OutFile $outFile

like image 66
Cale Vernon Avatar answered Dec 02 '25 18:12

Cale Vernon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!