节点红色js中的HTTP POST [英] HTTP POST in node-red js

查看:141
本文介绍了节点红色js中的HTTP POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用API​​密钥将带有JSON数据的http POST请求放入某个服务器。我在 http://nodered.org/docs/ 进行了搜索,但他们没有写清楚任何内容。文档非常混乱,甚至不太好理解。
但是,我试图POST一个字符串化的JSON数据:

I want to know how to do a http POST request with a JSON data into some server with API key. I searched in http://nodered.org/docs/ But they haven't written anything clearly. The documentation is very messy and not even good to understand. However, I have tried to POST a JSON data which is stringified:

{"version":"1.0.1","sensors":[{"sensor":"accel","output":[{"name":"accelert","type":"dcmotion"}]}]}

我已经在函数节点中编写了API(这里的API是仲裁的,不是原创的)

I have written the API in function node as (API is arbitary here, not original)

var msg = {"version":"1.0.1","sensors":[{"sensor":"accel","output":[{"name":"accelert","type":"dcmotion"}]}]}

msg.headers: {
                    'x-api-key': 'ucasdfeacceacxfAIH2L4=',
                    'content-type': 'application/json"
                }

我得到了这个例如: https://groups.google.com/forum /#!msg / node-red / nl9Be0dN55g / S_VYMTjOanEJ

我将输入节点添加为HTTP POST然后给出了url并将其连接到添加了一个的函数调试节点。
现在我部署了它。我收到错误:API节点中的意外令牌

And I added input node as HTTP POST then given the url and connected it with function added one debug node. Now I deployed it. I am getting error : Unexpected token in API node

现在我不知道该怎么做。我没有得到如何做到这一点。请帮帮我。节点红色站点中没有可用的教程。

Now I'm not sure how to do that. I am not getting how to do this. Please help me out. No tutorial available in node red site.

推荐答案

而不是 var msg = {... 你应该使用 msg.payload = {...

因为 msg 是节点红色节点之间传递的标准JSON对象消息,所以不应该使用var声明它的有效负载属性包含消息正文,因此当为 HTTP请求节点提供 msg 时,会发送有效负载属性作为请求的正文(请参阅 HTTP请求节点的信息选项卡)。

Because msg is a standard JSON object message passed between node-red nodes, so should not be declared using var, and its payload property contains the body of the message, so when the msg is provided for the HTTP request node the payload property is sent as the body of the request (see the info tab of the HTTP request node).

这篇关于节点红色js中的HTTP POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆