您希望访问传递到 HTTP 端点的查询参数,例如
http://example.com/hello-query?name=Nick
使用 HTTP In
节点发送的消息的 msg.req.query
属性来访问参数。
[{"id":"b34dd1af.4cb23","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 {{req.query.name}}!</h1>\n </body>\n</html>","x":290,"y":180,"wires":[["b828f6a6.47d708"]]},{"id":"1052941d.efad6c","type":"http in","z":"3045204d.cfbae","name":"","url":"/hello-query","method":"get","swaggerDoc":"","x":120,"y":180,"wires":[["b34dd1af.4cb23"]]},{"id":"b828f6a6.47d708","type":"http response","z":"3045204d.cfbae","name":"","x":430,"y":180,"wires":[]}]
[~]$ curl https://:1880/hello-query?name=Nick
<html>
<head></head>
<body>
<h1>Hello Nick!</h1>
</body>
</html>
msg.req.query
属性是一个包含每个查询参数键/值对的对象。
在上面的示例中,对 /hello-query?name=Nick&colour=blue
的请求将导致该属性包含
{
"name": "Nick",
"colour": "blue"
}
如果存在多个同名查询参数,它们将以数组形式提供。例如,/hello-query?colour=blue&colour=red
{
"colour": ["blue","red"]
}
版权所有 OpenJS Foundation 和 Node-RED 贡献者。保留所有权利。OpenJS Foundation 已注册商标并使用商标。有关 OpenJS Foundation 商标列表,请参阅我们的商标政策和商标列表。OpenJS Foundation 商标列表中未标明的商标和徽标是其各自持有者的商标™或注册®商标。使用它们并不意味着与它们有任何关联或得到它们的认可。
OpenJS Foundation | 使用条款 | 隐私政策 | OpenJS Foundation 章程 | 商标政策 | 商标列表 | Cookie 政策