【发布时间】:2016-03-02 13:35:29
【问题描述】:
我正在尝试使用 PowerShell 的 POST 请求。它需要原始类型的主体。我知道如何使用 PowerShell 传递表单数据,但不确定原始数据类型。对于 Postman 中的简单原始数据,例如
{
"@type":"login",
"username":"xxx@gmail.com",
"password":"yyy"
}
我在 PowerShell 中通过下面,它工作正常。
$rawcreds = @{
'@type' = 'login'
username=$Username
password=$Password
}
$json = $rawcreds | ConvertTo-Json
但是,对于如下所示的复杂原始数据,我不确定如何传入 PowerShell。
{
"@type": Sample_name_01",
"agentId": "00000Y08000000000004",
"parameters": [
{
"@type": "TaskParameter",
"name": "$source$",
"type": "EXTENDED_SOURCE"
},
{
"@type": "TaskParameter",
"name": "$target$",
"type": "TARGET",
"targetConnectionId": "00000Y0B000000000020",
"targetObject": "sample_object"
}
],
"mappingId": "00000Y1700000000000A"
}
【问题讨论】:
-
Invoke-WebRequest和Invoke-RestMethod的-Body参数接受一个字符串,并将其用作“原始正文”,所以我不确定我是否理解这个问题。 -
你的意思是,我可以通过下面给出的整个原始身体?
-
将所需的文字(原始)内容放入字符串中,然后将其传入。在第一个示例中,您创建一个对象,然后将其转换为 JSON(字符串)。您的“复杂”示例是否意味着原始 JSON?而你不确定如何构建它?
-
是的,没错。
标签: rest powershell powershell-5.0