Powershell相当于curl -F上传文件



我需要通过命令行/powershell上传文件。使用

就可以了
curl -F "file=@test.txt" https://api.anonfiles.com/upload

但是,curl在Windows Server 2016上不存在,我不想告诉我的客户端设置它。所以我正在寻找一个powershell替代来完成这个任务。我尝试了各种解决办法,但没有一个奏效。到目前为止我所尝试的:

(1)

$postParams = @{file='C:usersusertestfile.txt'}; Invoke-WebRequest -Uri https://api.anonfiles.com/upload -Method POST -Body $postParams

(2)

Invoke-WebRequest -UseBasicParsing https://api.anonfiles.com/upload -ContentType "application/json" -Method POST -InFile "C:usersusertestfile.txt"

(3)

$file=[io.file]::readallbytes('c:usersusertestfile.txt')
Invoke-WebRequest -UseBasicParsing https://api.anonfiles.com/upload -ContentType "application/json" -Method POST -Body "{ '@file':'"$file"'}"

都不起作用。我不敢相信在powershell中替换curl在线编辑器是如此困难…每种情况下的错误都是400 http错误,请求是错误的。我如何在powershell中发送上面提到的curl-request ?网址:https://anonfiles.com/docs/api

我放弃了。这在Powershell中是不可能的。我的应用程序将从现在开始下载独立的curl.exe,如果它不在那里。

最新更新