cURL到Invoke-Webrequest命令 [英] cURL to Invoke-Webrequest command
本文介绍了cURL到Invoke-Webrequest命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能给我一个提示,如何将以下curl命令转换为PS Invoke-Webrequest?
Can anyone give me a hint, how to convert following curl command to PS Invoke-Webrequest ?
curl -d {\"password\":\"$password\"\} $vault/v1/auth/userpass/login/${login,,}
我对此有一些想法,但无法弄清楚如何完成此操作:
I have some thoughts on this, but cannot figure out, how to finish this:
$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
如何正确地传递$ params,例如curl请求?
How to correctly pass $params like in curl request?
推荐答案
参数应为哈希表 @ {}
。
$Params = @{
Username="TestName";
Password="TestPassword";
Places = @("Here","There");
}
下面是使用名为jsonplaceholder的测试API的示例
Here is a example using a test API called jsonplaceholder
$url = 'https://jsonplaceholder.typicode.com/posts'
$params = @{
title: 'foo'
body: 'bar'
userId:1
}
(Invoke-WebRequest $url -Method Post -Body $params -UseBasicParsing).content | ConvertFrom-JSON
响应
id
title: 'foo'
body: 'bar'
userId:1
--------------------------------------------------- --
101
这篇关于cURL到Invoke-Webrequest命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文