Javascript 如何使用请求模块在nodejs中调用多个请求?
我想让它看起来更好, 我使用请求模块在同一台服务器上执行http请求,但使用不同的dev id来检索设备值 我有如下所示,但是否有其他方法将其包含在一个通话中 这就是我所拥有的:Javascript 如何使用请求模块在nodejs中调用多个请求?,javascript,node.js,request,Javascript,Node.js,Request,我想让它看起来更好, 我使用请求模块在同一台服务器上执行http请求,但使用不同的dev id来检索设备值 我有如下所示,但是否有其他方法将其包含在一个通话中 这就是我所拥有的: request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightnin
request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightning[1].ref2, (error, response, body) => {
let object = JSON.parse(body);});
request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightning[0].ref1, (error, response, body2) => {
let object2 = JSON.parse(body2);});
request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightning[0].ref3, (error, response, body3) => {
let object3 = JSON.parse(body3);});
request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightning[0].ref4, (error, response, body4) => {
let object3 = JSON.parse(body4);});
这里是我的脚本的一部分,我用它来:
// Issue the request
request("http://" + DEV_IP.DEV_IP + ":" + DEV_port.DEV_port + "/JSON?request=getstatus&ref=" + addons.Lightning[1].ref2, (error, response, body) => {
let object = JSON.parse(body);
request("http://" + DEV_IP.DEV_IP + ":" + DEV_port.DEV_port + "/JSON?request=getstatus&ref=" + addons.Lightning[0].ref1, (error, response, body2) => {
let object2 = JSON.parse(body2);
// If there has been an error, log it
if (error) console.error(error);
message.channel.send({
embed: {
color: 3447003,
author: {
name: "Malosa-Lightning add-on",
icon_url: "https://icons.iconarchive.com/icons/jaan-jaak/weather/256/thunder-lightning-storm-icon.png"
},
title: "Lightning Detection",
url: "http://google.com",
description: "Current live info",
fields: [{
name: "Detection:",
value: (object.Devices[0].status)
},
{
name: "Masked links",
value: "You can put [masked links](http://google.com) inside of rich embeds."
},
{
name: "Markdown",
value: "You can put all the *usual* **__Markdown__** inside of them."
}
],
timestamp: new Date(),
footer: {
icon_url: client.user.avatarURL,
text: "© Example"
}
}
});
});
});
我发现了
我把它改成axios
使用时
const [response1, response2 ,response3] = await axios.all([
axios.get("WEBSITE1"),
axios.get("WEBSITE2"),
axios.get("WEBSITE3"),
]);
console.log (response1)
console.log (response2)
console.log (response3)
; 不要使用它。我们无法知道您正在调用的API是否支持同时传递多个引用。您有更好的解决方案吗?如果是这样,你能告诉我怎么做吗。我在前面的评论中链接到的页面有指向备选方案的指针。我想要的是使用该模块一次,请求一个类似于[http request1,http resuest2,http request3]的站点,依此类推