Преобразовать команду curl в invoke-restmethod - PullRequest
0 голосов
/ 30 мая 2018

Я пытаюсь преобразовать следующую команду 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 голосов
/ 30 мая 2018

Вы передаете тело / данные через словарь, как показано ниже:

$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 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...