您希望将表单数据发布到流中。
使用 HTTP In
节点监听 Content-Type
设置为 application/x-www-form-urlencoded
的 POST 请求,并将表单数据作为 msg.payload
的属性进行访问。
[{"id":"5b98a8ac.a46758","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-form","method":"post","swaggerDoc":"","x":120,"y":820,"wires":[["bba61009.4459f"]]},{"id":"bba61009.4459f","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.name }}!</h1>\n </body>\n</html>","x":290,"y":820,"wires":[["6ceb930a.93146c"]]},{"id":"6ceb930a.93146c","type":"http response","z":"3045204d.cfbae","name":"","x":430,"y":820,"wires":[]}]
[~]$ curl -X POST -d "name=Nick" https://:1880/hello-form
<html>
<head></head>
<body>
<h1>Hello Nick!</h1>
</body>
</html>
HTML 表单可用于将数据从浏览器发送回服务器。如果配置为 POST
数据,浏览器将使用 content-type
为 application/x-www-form-urlencoded
对 <form>
中保存的数据进行编码。
例如,当提交如下所示的表单时
<form action="https://:1880/hello-form" method="post">
<input name="name" value="Nick">
<button>Say hello</button>
</form>
它将导致请求
POST / HTTP/1.1
Host: localhost:1880
Content-Type: application/x-www-form-urlencoded
Content-Length: 9
name=Nick
当 HTTP In
节点收到此类请求时,它会解析请求正文并将表单数据在 msg.payload
下提供
var name = msg.payload.name;
版权所有 OpenJS Foundation 和 Node-RED 贡献者。保留所有权利。OpenJS Foundation 已注册商标并使用商标。有关 OpenJS Foundation 商标列表,请参阅我们的 商标政策 和 商标列表。OpenJS Foundation 商标列表 中未注明的商标和徽标是其各自所有者的商标™ 或注册® 商标。使用它们不表示与它们有任何关联或认可。
The OpenJS Foundation | 使用条款 | 隐私政策 | OpenJS Foundation 章程 | 商标政策 | 商标列表 | Cookie 政策