• V
 

将原始数据发送到流程

问题

您想将原始文本数据发送到一个流程中。

解决方案

使用 HTTP In 节点监听具有 Content-Type 设置为 text/plain 的 POST 请求,并将发布的数据作为 msg.payload 访问。

示例

[{"id":"3e1c5107.c1e3ae","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-raw","method":"post","swaggerDoc":"","x":120,"y":920,"wires":[["cf679478.309868"]]},{"id":"cf679478.309868","type":"template","z":"3045204d.cfbae","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>Hello {{ payload }}!</h1>\n    </body>\n</html>","x":290,"y":920,"wires":[["f3c1a3f0.0c3e6"]]},{"id":"f3c1a3f0.0c3e6","type":"http response","z":"3045204d.cfbae","name":"","x":430,"y":920,"wires":[]}]
[~]$ curl -X POST -d 'Nick' -H "Content-type: text/plain" http://localhost:1880/hello-raw
<html>
    <head></head>
    <body>
        <h1>Hello Nick!</h1>
    </body>
</html>

讨论

HTTP In 节点接收到 Content-Type 头设置为 text/plain 的请求时,它会将请求体作为 msg.payload 提供:

var name = msg.payload;