【问题标题】:Subscribe to specific event in ASP.NET WebHooks订阅 ASP.NET WebHooks 中的特定事件
【发布时间】:2017-01-19 17:23:02
【问题描述】:

我正在尝试学习 ASP.NET WebHooks,但现在文档很少。

我想要做的是订阅一个特定的事件。我能找到的所有示例都演示了订阅所有事件,这对我来说不是很有用。

编辑:

这是我在文档中找到的订阅代码:

function subscribe() {
    $.ajax({
        type: "POST",
        url: "/api/webhooks/registrations",
        data: JSON.stringify({
            WebHookUri: "http://localhost:59927/api/webhooks/incoming/custom",
            Secret: "12345678901234567890123456789012",
            Description: "My first WebHook!"
        }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data, status) { alert(status); },
        failure: function(errMsg) { alert(errMsg); }
    });
    return false;
}

订阅“BookAdded”事件的代码应该是什么?

谢谢!

【问题讨论】:

    标签: asp.net asp.net-webhooks


    【解决方案1】:

    所以,对于其他正在寻找答案的人来说,应该这样做:

    function subscribe() {
       $.ajax({
           type: "POST",
           url: "/api/webhooks/registrations",
           data: JSON.stringify({
           WebHookUri: "http://localhost:59927/api/webhooks/incoming/custom",
           Secret: "12345678901234567890123456789012",
           Description: "My first WebHook!",
           Filters: ["BookAdded"]
        }),
        contentType: "application/json; charset=utf-8",
           dataType: "json",
           success: function(data, status) { alert(status); },
           failure: function(errMsg) { alert(errMsg); }
       });
       return false;
    }
    

    注意添加到 ajax 语句中的 Filters 字段。

    【讨论】:

    • 我们可以订阅 asp.net wehbooks 接收器本身吗?我想订阅 ebay 肥皂通知,我正在关注它的 asp.net.webhook.custom.receiver
    • 以上代码订阅了webhook项目内的事件,我们可以在当前项目外订阅吗?可能来自一个php项目?如何?我将上述请求发送到同事建立的自定义 webhook,但出现身份验证错误。在 URL 中,我提供完全限定的 URL。
    • 是的,它应该可以正常工作。身份验证错误与webhook机制无关,是服务器/站点的设置方式。
    猜你喜欢
    • 2015-11-06
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多