在Powershell中,Curl的@file是否等效?

时间:2019-03-08 00:07:28

标签: powershell curl

我有一个curl命令,如下所示:

curl -u secret: -X POST https://api.flood.io/floods \
-F "flood[tool]=jmeter" \
-F "flood[threads]=10" \
-F "flood[rampup]=60" \
-F "flood[duration]=300" \
-F "flood[privacy]=public" \
-F "flood[name]=Performance Test" \
-F "flood_files[]=@SitemapPerfTest.jmx" \
-F "flood[grids][][infrastructure]=demand" \
-F "flood[grids][][instance_quantity]=1" \
-F "flood[grids][][region]=us-west-2" \
-F "flood[grids][][instance_type]=m5.xlarge" \
-F "flood[grids][][stop_after]=5"

我试图在Powershell中编写等效的命令,但在@SitemapPerfText.jmx部分中苦苦挣扎。

这就是我要尝试的:

$username = "secret"
$password = ""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

$floodFile = [IO.File]::ReadAllText('SitemapPerfTest.jmx');

$params = @{
 "flood[tool]"="jmeter";
 "flood[threads]"="10";
 "flood[rampup]"="60";
 "flood[duration]"="300";
 "flood[privacy]"="public";
 "flood[name]"="Performance Test";
 "flood_files[]"="$floodFile";
 "flood[grids][][infrastructure]"="demand";
 "flood[grids][][instance_quantity]"="1";
 "flood[grids][][region]"="us-west-2";
 "flood[grids][][instance_type]"="m5.xlarge";
 "flood[grids][][stop_after]"="5";
}

Invoke-WebRequest -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Post -Uri "https://api.flood.io/floods" `
  -ContentType 'multipart/form-data' `
  -Body $params

但是,远程服务似乎无法识别我正在发送的文件。与cURL中的@file参数等效的powershell命令是什么?

0 个答案:

没有答案