首页 > 解决方案 > curl http请求到node-red

问题描述

我对 node-red 非常陌生,对向 node-red 发送 http 请求一无所知。我一直在尝试这种方法来向 node-red 发送请求,但它给了我状态码 0。

var xhr = new XMLHttpRequest();
xhr.open("POST", "https://my.node.com:port/endpoint", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
     data: "data"
}));
console.log(xhr.status);

我的上级建议我使用 curl 命令——我不知道该怎么做。由于时间有限,我不习惯使用 curl,也没有时间深入探索。我尝试使用此方法,但返回错误msg undefined

msg.payload = "data to post";
msg.headers = {};
msg.headers['content-type'] = 'application/json';
return msg;

如何向 node-red 发送 http 请求?

标签: javascripthtmlxmlhttprequestnode-red

解决方案


推荐阅读