将curl命令转换为invoke-restmethod

时间:2018-05-30 14:24:17

标签: powershell curl

我正在尝试将下一个curl命令转换为invoke-restmethod

curl -u USERNAME:PASSWORD -H 'X-Requested-With:ApiExplorer' 'https://LOCATION' -d 'action=fetch&id=1234567&output_format=CSV' > .\export.csv

但我坚持使用action=fetch&id=1234567&output_format=CSV'部分。

任何人都有一个想法

1 个答案:

答案 0 :(得分:0)

您通过字典传递正文/数据,如下所示:

$credentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("user:password"))

$headers = @{
    'X-Requested-With' = 'ApiExplorer'
    'Authorisation' = "basic $credentials" 
}

$body = @{
    action = 'fetch'
    id = '1234567'
    output_format = 'CSV'
}

Invoke-RestMethod -Method 'POST' -URI 'http:s//LOCATION' -Headers $headers -Body $body -ContentType application/x-www-form-urlencoded  -OutFile export.csv