如何将此cURL请求转换为powershell脚本?

时间:2016-11-10 16:37:41

标签: rest powershell curl post

以下是根据API文档中的示例应该运行的cURL请求:

curl
  -X POST
  -F "url=http://example.com/myjs.min.js" 
  -F "file=@C:\website\js\myjs.min.js"  
  https://restApi/endPoint

这是我尝试过的但它不起作用( - > 400 Bad Request):

$uri = 'https://restApi/endPoint'
$file = Get-Item C:\website\js\myjs.min.js
$body = @{
    url = 'http://example.com/myjs.min.js'
    file = $file
}
Invoke-RestMethod -Method Post -Uri $uri -Body $body

我在这里错过了什么/做错了什么?我假设它是我将文件分配给$body的部分,但我不知道应该如何修复它。

修改

已更改$file = Get-Content C:\website\js\myjs.min.js -raw,但仍然无效。还仔细看了一下我从服务器回来的响应,它说:

  

没有文件存在,请确保使用参数名称“file”发布文件。

但是“文件”设置在正文中,为什么它会抱怨?

0 个答案:

没有答案