【问题标题】:strange cors issue with socket io套接字 io 的奇怪 cors 问题
【发布时间】:2016-09-03 03:23:05
【问题描述】:

我正在使用 btford.socket-io,并尝试与 node 对话。

一切正常,但在我从 localhost:5000 更改为 example.org 之后就不行了,如下所示:

.factory('socket',function(socketFactory){
     //working
     var myIoSocket = io.connect('http://localhost:5000');
     //not working
     var myIoSocket = io.connect('http://example.org:5000');

      mySocket = socketFactory({
        ioSocket: myIoSocket
      });

    return mySocket;
})

我的控制台出现了这个错误

XMLHttpRequest cannot load http://example.com:5000/socket.io/?EIO=3&transport=polling&t=LIGH5VO. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8100' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.
:8100/#/app/completed:1 XMLHttpRequest cannot load http://example.com:5000/socket.io/?EIO=3&transport=polling&t=LIGH7BS. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8100' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.

我还尝试在我的快递中使用this npm 设置cors({origin:"*"}),但没有运气。

【问题讨论】:

    标签: angularjs node.js sockets express cors


    【解决方案1】:

    关于这个A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.

    将允许来源设置为固定域将解决此问题,目前,如果我没记错的话,http://example.org:5000。我认为您应该包括端口号。

    我不明白的是为什么你有标题凭据。

    【讨论】:

    • 在哪里?我无法设置,因为我来自客户端的请求是移动应用程序,没有任何域。
    • 我已经在我的套接字客户端中设置了example.org:5000。包含端口号是什么意思?
    • cors()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    相关资源
    最近更新 更多