[英]Set withCredentials attribute for XMLHttpRequest in Socket.io
I'm getting the following error using socket.io 我在使用socket.io时遇到以下错误
XMLHttpRequest cannot load https://******:3000/socket.io/?
EIO=3&transport=polling&t=LPBFdGH. A wildcard '*' cannot be used in the 'Access-Cont
rol-Allow-Origin' header when the credentials flag is true.
Origin 'https://*****.com' is therefore not allowed
access. The credentials mode of an XMLHttpRequest is controlled by the
withCredentials attribute
I've used CORS to set the attribute to no avail. 我已经使用CORS将属性设置为无效。
app.use(cors({ origin: true, credentials: true })); app.use(cors({origin:true,凭据:true}));
Are there are any other methods? 还有其他方法吗?
A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.
The key point here is that the origin:true
part of your CORS configuration produces a *
value for the Access-Control-Allow-Origin
header. 这里的关键点在于,CORS配置的
origin:true
部分会为Access-Control-Allow-Origin
标头生成一个*
值。 This is not acceptable when using the withCredentials
attribute for the XHR request in socket.io. 当对socket.io中的XHR请求使用
withCredentials
属性时,这是不可接受的。
You need to explicitly allow the origin, for example like this: 您需要显式允许原点,例如:
app.use(cors({ origin: 'https://******.com', credentials: true }));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.