如何在 Powershell 中 HTTP PUT 文件并捕获响应正文?

How to HTTP PUT a file in Powershell and capture response body?

我想使用 powershell 上传文件并捕获生成的响应正文。如何做到这一点?

我试过:

$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

但这不起作用并说 Command executed with exception: 没有列出异常。

使用 Invoke-RestMethod 命令进行探索。您可以使用 -OutFile 参数保存响应正文。

一个例子 PUT 如下,其中 $uri 是目的地,$inFile 是本地文件的路径,$outFile 是到哪里的路径保存响应正文:

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