0

查看了一些如何使用参数执行 webhook 的示例,但似乎无法与我所缺少的内容建立联系。任何关于我做错了什么的建议将不胜感激。

请考虑:我的 Powershell 运行手册

[CmdletBinding()]
Param([object]$WebhookData) #this parameter name needs to be called 
WebHookData otherwise the webhook does not work as expected.

$VerbosePreference = 'continue'
Write-Output "hello"
    "in the inline"
    if($WebhookData -ne $null) 
        {
            "using webhookdata"
            $WebhookName =  $WebhookData.WebhookName
            $WebhookBody =  $WebhookData.RequestBody
            $webhookBodyObject = $WebhookBody | ConvertFrom-JSON


line 15            'The parameter created was ' $webhookBodyObject.strYear

我的 httpclient 发布请求看起来像这样(警告..its vb)

dim WebHookData as new StringContent("{'strYear'='2018'}",Encoding.UTF8,"application/json")

        Dim resp as Task(Of HttpResponseMessage)
        resp = _client.PostAsync(webhook,WebHookData)
        status = resp.Result.Content.ReadAsStringAsync().Result
        if(status.Contains("JobId"))
            status = "Scheduled!"
        End If

我的 Webhook 数据正像这样发布到我的 Webhook。

{"WebhookName":"myimportjob","RequestBody":"{'strYear'='2018'}","RequestHeader":{"Connection":"Keep-Alive","Expect":"100-continue","Host":"xxx.azure-automation.net","x-ms-request-id":"xxx"}}

我收到此错误

在 line:15 char:42 + '创建的参数是 ' $webhookBodyObject.strYear + ~~~~~~~~~~~~~~~~~~ 表达式或语句中的意外标记 '$webhookBodyObject'。

4

1 回答 1

0

我发现魔鬼在细节中。首先我有

$webhookBodyObject = $WebhookBody | ConvertFrom-JSON

这与

$webhookBodyObject = $WebhookBody | ConvertFrom-Json <---this is the correct syntax

另一个是我发送的 json 有一个像这样的单引号 '{"key":"value"}'

出于某种原因,即使它通过了常规的 powershell,runbook 也不喜欢它。它希望它是像这样 {"key":"value"} 的 Json。我从来没有测试过复杂的对象,所以我不能说。

于 2018-05-04T03:04:43.510 回答