0

根据Whitesource 文档,响应标头将具有

Content-Type = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content-Disposition: attachment; filename=<product name>.xslx 

我想提取那个 xslx 文件,但是我不知道如何提取。我尝试将响应写入文件,但我得到的只是一堆二进制字符。

Invoke-RestMethod -SkipCertificateCheck -Method Post -ContentType 'application/json' -Body $body -Uri "https://app.whitesourcesoftware.com/api/v1.3 | Out-File "abcd.csv"

我还尝试在编写响应之前将其转换为 csv,但这也不起作用。

Invoke-RestMethod -SkipCertificateCheck -Method Post -ContentType 'application/json' -Body $body -Uri "https://app.whitesourcesoftware.com/api/v1.3 | ConvertTo-CSV | Out-File "abcd.csv"

任何想法?

4

1 回答 1

0

经过一番挖掘,我意识到该文件存在于contentrespose 的一部分中。我用Invoke-WebRequest而不是Invoke-RestMethod. 这是我的脚本:

$response = Invoke-WebRequest -Method Post -ContentType 'application/json' -Body $body -Uri $server
[System.IO.File]::WriteAllBytes("report.xlsx", $response.content)

这会将附件写入一个名为report.xlsx.

于 2020-01-20T06:32:16.723 回答