我有一个REST调用(POST)用于下载PDF文件。API调用响应二进制版本的PDF文件。我想将文件保存在我的机器上作为.pdf文件。但是,我遇到了一个错误:
Out-File:拒绝访问路径“C:\ Users \ my-name \ Documents \ Tests”。 在C:\ Users \ my-name \ Documents \ Tests \ TEST-WITH-LOOP.ps1的132个字符:149 + ... questBody | Out-File -FilePath(“C:\ Users \ my-name \ Documents \ Tests + 〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 + CategoryInfo:OpenError:[Out-File],UnauthorizedAccessException + FullyQualifiedErrorId:FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
POSTMAN的响应体头:
Content-Disposition →attachment; filename="Report-01_29_14-28.pdf" Content-Type →application/octet-stream DataServiceVersion →2.0 Date →Mon, 29 Jan 2018 21:51:31 GMT Date →Mon, 29 Jan 2018 21:51:31 GMT Server →Jetty(9.3.7.v20160115NeotysEdition.30) Transfer-Encoding →chunked
命令:
Out-File:拒绝访问路径“C:\ Users \ my-name \ Documents \ Tests”。 在C:\ Users \ my-name \ Documents \ Tests \ TEST-WITH-LOOP.ps1的132个字符:149 + ... questBody | Out-File -FilePath(“C:\ Users \ my-name \ Documents \ Tests + 〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 + CategoryInfo:OpenError:[Out-File],UnauthorizedAccessException + FullyQualifiedErrorId:FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
POSTMAN的响应体头:
Content-Disposition →attachment; filename="Report-01_29_14-28.pdf" Content-Type →application/octet-stream DataServiceVersion →2.0 Date →Mon, 29 Jan 2018 21:51:31 GMT Date →Mon, 29 Jan 2018 21:51:31 GMT Server →Jetty(9.3.7.v20160115NeotysEdition.30) Transfer-Encoding →chunked
命令:
$DownloadReportResponse = Invoke-RestMethod -Method Post -Uri $DownloadReportUrl -ContentType "application/json" -Body $DownloadReportRequestBody |
Out-File -FilePath ("C:\Users\my-name\Documents\Tests") -Force
问题: 如何将此文件保存为.pdf格式或作为附件包含在电子邮件中?