Node Red中的初学者。寻找一些使用
的例子 inject/timestamp node
和http in node
通过http response
输出到html。
我能够在debug node
中获取时间戳输出,但http response
节点返回
“无响应对象”
流程代码
[
{
"id": "9f006bd1.640c3",
"type": "http response",
"z": "d5fed3fc.0eb49",
"name": "",
"x": 897.2000122070312,
"y": 167.1999969482422,
"wires": [ ]
},
{
"id": "e3c543a2.edb15",
"type": "function",
"z": "d5fed3fc.0eb49",
"name": "setHTTPheader",
"func": "// If sending JSON data the content type is:\n//msg.headers={\"Content-Type\":\"application/json\"}\n\n// For HTML use the content type line below:\nmsg.headers={\"Content-Type\":\"text/html\"}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 530.2000122070312,
"y": 178.1999969482422,
"wires": [ [ "9f006bd1.640c3", "148ad3e4.c6b5bc" ] ]
},
{
"id": "30bfd46d.90b3fc",
"type": "inject",
"z": "d5fed3fc.0eb49",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": true,
"x": 214.1999969482422,
"y": 118.19999694824219,
"wires": [ [ "e3c543a2.edb15" ] ]
},
{
"id": "974e0c4.06af17",
"type": "http in",
"z": "d5fed3fc.0eb49",
"name": "/time",
"url": "/time",
"method": "get",
"swaggerDoc": "",
"x": 199.5,
"y": 175.40000915527344,
"wires": [ [ "e3c543a2.edb15" ] ]
},
{
"id": "148ad3e4.c6b5bc",
"type": "debug",
"z": "d5fed3fc.0eb49",
"name": "",
"active": true,
"console": "false",
"complete": "payload",
"x": 895.5000457763672,
"y": 211.8000030517578,
"wires": [ ]
}
]
答案 0 :(得分:2)
嗯,如果我理解你的问题,我不是百分百确定,但如果你想知道为什么会这样做
“无响应对象”
当触发左上角inject node
时,简单的答案是因为没有http response
对象将输出写入 - 只有当你通过左下方{{1}触发流时它才存在}节点。在您的示例中,您可以通过在浏览器中打开http://localhost:1880/time来触发它(假设您使用默认端口运行)。
如果您始终希望在回复中看到当前时间戳,只需在http in
中添加以下内容:
function node