【问题标题】:Passing notifications received from webhooks to the application react native将从 webhook 收到的通知传递给应用程序反应原生
【发布时间】:2020-11-15 13:30:26
【问题描述】:

我在 react native 中使用 webhook 和 ngrok 和 express,但我在使用 webhook 时遇到了问题。 我希望每当通过 webhook 在服务器中收到通知时更新应用程序(例如 App.js),这样我就可以在发生特定事件时更新平面列表。 我知道如何在服务器中接收 webhook,但我找不到将这些信息传递给应用程序的方法。 我错过了什么或者我走错了路,如果是这样,还有哪些其他选项可以将通知传递给应用程序。 我尝试了 app.post() 与任何其他 API 一样,但它不起作用。

提前谢谢你。

下面是服务器代码


app.post('/webhook', async function (req, res) {
    try {
        console.log("got webhook" + req + "   type: " + req.body.message_type);
        if (req.body.message_type === 'credential_offer') {
                    console.log("New Credential Offer");

以下是我在应用程序中尝试过的

axios.get('/webhook').then((response) => {
    console.log(response);
    const data=  fetchCredentials();
     setCredentials(data);
     console.log(credentials)
  });

【问题讨论】:

    标签: react-native server axios webhooks ngrok


    【解决方案1】:

    Express 的 app.post 处理 POST 请求,而 axios.get 发送 GET 请求。要使用 axios 从 react 向服务器发起 POST 调用,请使用 axios.post。

    【讨论】:

    • 我试过了,但它不起作用。问题是我需要应用程序处于活动状态,每当收到通知时,我都希望应用程序知道,因此 axios.post() 只能工作 1 次。
    猜你喜欢
    • 1970-01-01
    • 2018-07-03
    • 2019-05-16
    • 2018-10-23
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多