【问题标题】:GatewayScript request and not wait for responseGatewayScript 请求而不等待响应
【发布时间】:2021-10-04 08:14:13
【问题描述】:

是否可以对外部 rest API 进行 GET/POST 调用而不等待响应?

【问题讨论】:

    标签: node.js ibm-datapower


    【解决方案1】:

    GatewayScript urlopen 有一个回调,所以你不能只是“忽略”我假设的回调,至少我想不出一种方法来做到这一点.. 回调有两个参数,errorresponse,如果你不给他们你会得到一个错误。

    urlopen.open('http://example.com/mydoc.json', function (error, response) {
    });
    

    【讨论】:

      【解决方案2】:

      使用如下的异步调用,例如 fetch、await 或 promise:

      fetch(myRequest)
      .then(function(response) {
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
        return response.blob();
      })
      .then(function(response) {
        //retrieve your data her from the response object
      });
      

      【讨论】:

      • DataPower 有自己的模块/功能实现。不支持抓取。
      猜你喜欢
      • 2011-01-12
      • 2015-01-06
      • 1970-01-01
      • 2012-12-30
      • 2014-04-24
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多