Node.js Nativescript Socketio外部标头丢失
我尝试通过SocketioV4NativeScript-nodejs对我的用户进行身份验证 安装程序 客户端 我写了这个app.module.tsNode.js Nativescript Socketio外部标头丢失,node.js,angular,socket.io,cors,nativescript,Node.js,Angular,Socket.io,Cors,Nativescript,我尝试通过SocketioV4NativeScript-nodejs对我的用户进行身份验证 安装程序 客户端 我写了这个app.module.ts SocketIOModule.forRoot('http://10.0.2.2:3000', { debug: true, log: true, extraHeaders: { 'authorization': `Bearer ${getString('ACCESS_TOKEN')}` }, }), 只需this.socke
SocketIOModule.forRoot('http://10.0.2.2:3000', {
debug: true,
log: true,
extraHeaders: {
'authorization': `Bearer ${getString('ACCESS_TOKEN')}`
},
}),
只需this.socketIO.connect()代码>
问题
问题是我的服务器根本没有收到我的ExtraHeader。我无法正确地进行身份验证
我的研究
使用Chrome开发工具进行调试,我的websocket请求根本不会被记录。
通过添加console.log('url',args)代码>位于index.android.js(nativescript socketio lib)的第73行。
上面this.socket=io.socket.client.io.socket(args[0],opts.build())代码>
标题正确显示
通过检查服务器接收的内容
{
accept: '*/*',
host: '10.0.2.2:3000',
connection: 'Keep-Alive',
'accept-encoding': 'gzip',
'user-agent': 'okhttp/3.12.12'
}
使用其他工具:
服务器正确地接收头
{
host: 'localhost:3000',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0',
accept: '*/*',
'accept-language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'accept-encoding': 'gzip, deflate',
authorization: 'Bearer eyJhbGciOiJIU............V4MKGQ',
origin: 'https://amritb.github.io',
connection: 'keep-alive',
'sec-gpc': '1'
}
最后,我认为这是一个CORS问题(我认为不太可能,因为没有错误)。我的服务器套接字使用以下选项。如报告中所述
我发现了类似的问题,但他们的解决方案并没有改变任何事情
有人曾经面对过这个问题吗?你还有别的想法吗?我没有主意了
感谢您的帮助如果它只影响授权标头,您是否尝试过
您是否可以尝试使用凭据
=true
我使用另一个标题测试了“test”:“test”
,并且也不会出现在服务器端。nativescript socketio lib中没有“withCredentials”选项,我尝试了“secure”:true,但仍然不起作用
{
host: 'localhost:3000',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0',
accept: '*/*',
'accept-language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'accept-encoding': 'gzip, deflate',
authorization: 'Bearer eyJhbGciOiJIU............V4MKGQ',
origin: 'https://amritb.github.io',
connection: 'keep-alive',
'sec-gpc': '1'
}
{
cors: {
origin: '*',
allowedHeaders: ['authorization']
}
}
}