接口操作-访问请求头
获取访问接口的请求头信息
接口路由访问规则参考 接口操作-创建接口
问题背景
访问接口访问中携带的请求头信息
解决方案
使用 接口定义 节点发送消息的 msg.req.headers 属性来访问标头。
msg.req.headers 属性是每个请求标头的键/值对对象。标头名称无论在请求中如何出现,均采用小写形式。
示例
示例JSON
[{"id":"c1460268.3eba","type":"http in","z":"65b5dbf44a0ca401","name":"","url":"/hello-headers","method":"get","upload":false,"swaggerDoc":"","advancedoptions":false,"apiAuth":"public","x":170,"y":1040,"wires":[["24199456.dbe66c"]]},{"id":"24199456.dbe66c","type":"template","z":"65b5dbf44a0ca401","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n <head></head>\n <body>\n <h1>User agent: {{req.headers.user-agent}}</h1>\n </body>\n</html>","x":430,"y":1040,"wires":[["55a25951a95ee70d"]]},{"id":"55a25951a95ee70d","type":"http response","z":"65b5dbf44a0ca401","name":"接口响应","statusCode":"","headers":{},"commonTemplate":false,"responseCode":0,"responseCodeType":"num","responseData":"payload","responseDataType":"msg","responseMsg":"success","responseMsgType":"str","x":700,"y":1040,"wires":[]}]
运行结果
在浏览器访问以上示例定义的接口:https://192.168.108.251:8080/prod-api/noco-instance/stotest/public/hello-headers

在流程中打印请求头信息:
