【发布时间】:2021-10-04 08:14:13
【问题描述】:
是否可以对外部 rest API 进行 GET/POST 调用而不等待响应?
【问题讨论】:
标签: node.js ibm-datapower
是否可以对外部 rest API 进行 GET/POST 调用而不等待响应?
【问题讨论】:
标签: node.js ibm-datapower
GatewayScript urlopen 有一个回调,所以你不能只是“忽略”我假设的回调,至少我想不出一种方法来做到这一点..
回调有两个参数,error 和 response,如果你不给他们你会得到一个错误。
urlopen.open('http://example.com/mydoc.json', function (error, response) {
});
【讨论】:
使用如下的异步调用,例如 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
});
【讨论】: