【发布时间】:2021-04-10 11:16:04
【问题描述】:
我正在尝试使用 socket.io 连接到远程服务器,但我遇到了一些问题。我收到此错误:响应中 Access-Control-Allow-Credentials 标头的值是“”,当请求的凭据模式为“包含”时,它必须为“真”
好的,代码如下:
服务器
var server = require('http').createServer();
const io = require("socket.io")(server, {
cors: {
origin: "my URL",
methods: ["GET", "POST"],
credentials: false
}
});
io.sockets.on('connection', function(socket) {
console.log("Client has connected!");
});
console.log ('Server started.');
server.listen(3000);
这是客户端代码:
var socket = io.connect("https://persistent-gentle-banon.glitch.me", {
withCredentials: false
});
我怎样才能解决这个问题并让它连接?
感谢您的帮助!
【问题讨论】:
标签: javascript node.js socket.io