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.
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