将简单的curl数据请求转换为Powershell invoke-webrequest [英] convert simple curl data request to powershell invoke-webrequest
问题描述
将非常简单的Plaid API curl数据请求转换为Powershell invoke-webrequest
Converting a very simple Plaid API curl data request to a powershell invoke-webrequest
有效方法:
curl -X POST https://tartan.plaid.com/balance \
-d client_id=client-id-value \
-d secret=secret-value \
-d access_token=access-token-value
我在Powershell中尝试失败的内容
What I'm trying unsuccessfully in Powershell
#test powershell api call
$hash = @{ client_id = "client-id-value";
secret = "secret-value"
access_token = "access-token-value"
}
$JSON = $hash | convertto-json
#Invoke-WebRequest -uri "https://tartan.plaid.com/balance" -Method POST -Body $JSON
这将返回一个格子错误1100(缺少客户端ID),因此我知道某些API功能正在运行,但是它不能正确解析输入数据.
This returns a plaid error 1100 (client id missing), so I know some API functionality is working, but it's not parsing input data correctly.
我最大的误解是如何将"curl -data"值转换为正确的Powershell参数.
My biggest misunderstanding is how to translate a "curl -data" value into the proper Powershell parameter.
这是标头值,正文值吗?等等
Is this a header value, body value? etc.
推荐答案
除非目标URL期望POST正文为JSON格式,否则请完全跳过ConvertTo-JSON
步骤.
Unless the target url expects the POST body to be in JSON format, skip the ConvertTo-JSON
step completely.
当所选择的HTTP方法是
When the chosen HTTP method is POST
, Invoke-WebRequest
will automatically take all the keys in the hashtable supplied to the -Body
parameter and construct a body payload similar to that of curl -d
:
$POSTParams = @{
client_id = "client-id-value"
secret = "secret-value"
access_token = "access-token-value"
}
Invoke-WebRequest -Uri "https://tartan.plaid.com/balance" -Method POST -Body $POSTParams
这篇关于将简单的curl数据请求转换为Powershell invoke-webrequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!