如何使用PowerShell Invoke-RestMethod发送multipart / form-data
发布时间:2020-05-23 23:29:30 所属栏目:Linux 来源:互联网
导读:我正在尝试通过Invoke-RestMethod发送一个文件,类似于curl与-F开关的上下文. 卷曲示例 curl -F FileName=@/path-to-file.name https://uri-to-post 在powerhell中,我尝试过这样的事情: $uri = https://uri-to-post$contentType = multipart/form-da
|
我正在尝试通过Invoke-RestMethod发送一个文件,类似于curl与-F开关的上下文. 卷曲示例 curl -F FileName=@"/path-to-file.name" "https://uri-to-post" 在powerhell中,我尝试过这样的事情: $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需要一些其他参数.初始请求需要一些参数来接受原始内容并指定filename / size.设置完毕并获取正确的链接后,我可以使用:Invoke-RestMethod -Uri $uri -Method Post -InFile $filePath -ContentType "multipart/form-data" (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
