任何人都可以给我一个提示,如何将以下curl命令转换为PS Invoke-Webrequest?
curl -d {\"password\":\"$password\"\} $vault/v1/auth/userpass/login/${login,,}
我对此有一些想法,但无法弄清楚如何完成此操作:
$vault="3.3.3.3:8500"
$pair = (Get-Credential)
$params = ????
$login = $pair.getNetworkCredential().username
$pass = $pair.getNetworkCredential().password
Invoke-WebRequest $url -Method Post -Credential $pair -Body $params -UseBasicParsing
如何像curl请求一样正确传递$ params?
答案 0 :(得分:2)
参数应为哈希表default_max_page_size
。
@{}
以下是使用名为jsonplaceholder的测试API的示例
$Params = @{
Username="TestName";
Password="TestPassword";
Places = @("Here","There");
}
响应
$url = 'https://jsonplaceholder.typicode.com/posts'
$params = {
title: 'foo'
body: 'bar'
userId:1
}
(Invoke-WebRequest $url -Method Post -Body $params -UseBasicParsing).content | ConvertFrom-JSON