如何在 Sails 1 中访问操作 2 header?
How can I access an action 2 header in Sails 1?
Sails 1 中的 Action 2 是一些非常新的东西,但我正在努力用它开发应用程序。但是,在做一些过程的时候,比如token attention,我需要访问来自请求header的token,因为Action 2只接收输入和退出,所以我无法访问请求及其header 和他们在一起。任何可以帮助我提供退出创建材料的人也会有很大的帮助。我愿意为未来的开发人员写下我的发现。
使用actions2,您可以使用this.req
访问请求对象。
您可以在操作方法中通过 this.req.headers 访问 header。
fn: async function (inputs, exits) {
sails.log.debug(inputs);
sails.log.debug(this.req.headers);
...
}
输出将类似于:
debug: { 'content-type': 'application/json', token:
'3f892682b21d4a649cc93e541b1b05405512eee6', 'cache-control':
'no-cache', 'postman-token': 'eafa2bc7-5576-4acb-8f8d-91ebc9365e32',
'user-agent': 'PostmanRuntime/7.6.0', accept: '/', host:
'localhost:1337', cookie:
'sails.sid=s%3AUIHK5FhQjC-prYvonucFBR4hnrxgNO8R.kvoR4EMgzR2%2F%2Btg8pIFKNcsmYgPQsn6xOQp5aSmJuX4',
'accept-encoding': 'gzip, deflate', 'content-length': '62',
connection: 'keep-alive' }
请查看官方文档:https://sailsjs.com/documentation/reference/request-req/req-headers
Sails 1 中的 Action 2 是一些非常新的东西,但我正在努力用它开发应用程序。但是,在做一些过程的时候,比如token attention,我需要访问来自请求header的token,因为Action 2只接收输入和退出,所以我无法访问请求及其header 和他们在一起。任何可以帮助我提供退出创建材料的人也会有很大的帮助。我愿意为未来的开发人员写下我的发现。
使用actions2,您可以使用this.req
访问请求对象。
您可以在操作方法中通过 this.req.headers 访问 header。
fn: async function (inputs, exits) {
sails.log.debug(inputs);
sails.log.debug(this.req.headers);
...
}
输出将类似于:
debug: { 'content-type': 'application/json', token: '3f892682b21d4a649cc93e541b1b05405512eee6', 'cache-control': 'no-cache', 'postman-token': 'eafa2bc7-5576-4acb-8f8d-91ebc9365e32', 'user-agent': 'PostmanRuntime/7.6.0', accept: '/', host: 'localhost:1337', cookie:
'sails.sid=s%3AUIHK5FhQjC-prYvonucFBR4hnrxgNO8R.kvoR4EMgzR2%2F%2Btg8pIFKNcsmYgPQsn6xOQp5aSmJuX4', 'accept-encoding': 'gzip, deflate', 'content-length': '62',
connection: 'keep-alive' }
请查看官方文档:https://sailsjs.com/documentation/reference/request-req/req-headers