我正在尝试通过Invoke-RestMethod在与-F开关curl相似的上下文中发送文件。
卷曲示例
curl -F FileName=@"/path-to-file.name" "https://uri-to-post"
在powershell中,我已经尝试过类似的方法:
$uri = "https://uri-to-post"
$contentType = "multipart/form-data"
$body = @{
"FileName" = Get-Content($filePath) -Raw
}
Invoke-WebRequest -Uri $uri -Method Post -ContentType $contentType -Body $body
}
如果我检查提琴手,我会看到主体包含原始二进制数据,但返回200响应,表明未发送任何有效负载。
我也尝试过使用-InFile参数,但没有运气。
我已经看到了许多使用.net类的示例,但是试图通过较新的Powershell 3命令使其保持简单。
有人有做这项工作的指导或经验吗?
这里的问题是API需要一些其他参数。初始请求需要一些参数来接受原始内容并指定文件名/大小。设置好并返回正确的链接以提交后,我可以使用:
Invoke-RestMethod -Uri $uri -Method Post -InFile $filePath -ContentType "multipart/form-data"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句