HTTPリクエストのヘッダを指定したい。
リクエストヘッダに含めたい内容を msg.headers
フィールドにセットして
HTTP request
ノードで送信します。
[{"id":"92272f91.20a43","type":"inject","z":"c9a81b70.8abed8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":760,"wires":[["af92df2f.3032e"]]},{"id":"64da113d.24a75","type":"http request","z":"c9a81b70.8abed8","name":"post to FRED","method":"POST","ret":"txt","url":"http://mike.fred.sensetecnic.com/api/test","tls":"","x":520,"y":760,"wires":[["31ab53be.5111dc"]]},{"id":"af92df2f.3032e","type":"function","z":"c9a81b70.8abed8","name":"set payload and headers","func":"msg.payload = \"data to post\";\nmsg.headers = {};\nmsg.headers['X-Auth-User'] = 'mike';\nmsg.headers['X-Auth-Key'] = 'fred-key';\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":760,"wires":[["64da113d.24a75"]]},{"id":"31ab53be.5111dc","type":"debug","z":"c9a81b70.8abed8","name":"","active":true,"console":"false","complete":"false","x":690,"y":760,"wires":[]}]
この例では、FREDというNode-REDのクラウドサービス内のプライベートなHTTP inputノードを呼び出す際に
リクエストヘッダに X-Auth-User
と X-Auth-Key
をセットしています。
次に示す Function
ノードのコードでは、
msg.headers
オブジェクトに追加のメッセージフィールドを追加し、
その中にリクエストヘッダのフィールドと値をセットしています。
msg.payload = "data to post";
msg.headers = {};
msg.headers['X-Auth-User'] = 'mike';
msg.headers['X-Auth-Key'] = 'fred-key';
return msg;
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy