本文介绍了netty socket io CORS错误:Access-Control-Allow-Origin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有wamp服务器运行https,java netty socket.io服务器通过SSL和socket.io客户端保护。

I have wamp server running https, java netty socket.io server secured by SSL, and socket.io client.

在客户端我有下面的代码: p>

In client I have folowing code:

io.connect(url, {secure: true} );

网址是:

当我在浏览器中打开我的网络服务器:
我遇到以下错误:

When I open in my browser my webserver: https://127.0.0.1I have following error:

socket.io-client:manager reconnect attempt error +1ms
socket.io.js (wiersz 1284)
socket.io-client:manager will wait 4000ms before reconnect attempt +1ms
socket.io.js (wiersz 1284)
engine.io-client:socket socket close with reason: "transport error" +3ms
socket.io.js (wiersz 3524)
engine.io-client:polling transport not open - deferring close +1ms
socket.io.js (wiersz 3524)
socket.io-client:manager attempting reconnect +4s
socket.io.js (wiersz 1284)
socket.io-client:manager readyState closed +3ms
socket.io.js (wiersz 1284)
socket.io-client:manager opening https://127.0.0.1:8080 +5ms
socket.io.js (wiersz 1284)
engine.io-client:socket creating transport "polling" +4s
socket.io.js (wiersz 3524)
engine.io-client:polling polling +5ms
socket.io.js (wiersz 3524)
engine.io-client:polling-xhr xhr poll +4ms
socket.io.js (wiersz 3524)
engine.io-client:polling-xhr xhr open GET:           https://127.0.0.1:8080/socket.io/?EIO=3&transport=polling&t=1433329575886-4 +4ms
socket.io.js (wiersz 3524)
engine.io-client:polling-xhr xhr data null +6ms
socket.io.js (wiersz 3524)
GET https://127.0.0.1:8080/socket.io/?   EIO=3&transport=polling&t=1433329575886-4

    37ms
socket.io.js (wiersz 2739)
engine.io-client:socket setting transport polling +13ms
socket.io.js (wiersz 3524)
socket.io-client:manager connect attempt will timeout after 20000 +42ms
socket.io.js (wiersz 1284)
Zablokowano żądanie do zasobu innego pochodzenia: zasady „Same Origin   Policy" nie pozwalają wczytywać zdalnych zasobów z    „https://127.0.0.1:8080/socket.io/?EIO=3&transport=polling&t=1433329575886-  4". (nieudane żądanie CORS)
engine.io-client:socket socket error      {"type":"TransportError","description":0} +151ms
 socket.io.js (wiersz 3524)
 socket.io-client:manager connect_error +145ms

我不知道这个错误的原因

I don't know cause of this error... It's error on client, server or javascript is blocking something?

我的错误是在波兰,但在英语是这样的:

my error is in polish but in english is something like this:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8008/socket.io/1/?t=1399898337175. This can be fixed by moving the resource to the same domain or enabling CORS.

但我的资源在同一个域。

But my resources are on the same domain.

你知道如何解决问题吗?
我读到添加访问控制允许原因标题可以解决这个问题。如何添加到netty java socket.io实现?

Do you know how to resolve the problem?I read that adding "Access-Control-Allow-Origin" to header could fix this. How add that to netty java socket.io implementation?

编辑

我添加到标题:Access-Control-Allow-Origin:*
,并且错误仍然出现

I added to header: Access-Control-Allow-Origin: "*"and error still occurs

推荐答案

I已自行签署SSL凭证,而我的浏览器封锁了以下项目的要求:

I had self signed SSL certificate, and my browser blocked requests from:https://127.0.0.1:8080/socket.io/?EIO=3&transport=polling&t=1433329575886-4

所以我在浏览器中输入:
并且我接受了自签名证书,它工作。

so I entered in browser: https://127.0.0.1:8080/socket.io/?EIO=3&transport=polling&t=1433329575886-4and I accepted self signed certificate, and it worked.

在正常的SSL证书上,一切都是正常的。

On normal SSL certificate everything worked out of box.

也有类似于_config.setOrigin href =http:// WebServerHost:WebServerPort =nofollow> http:// WebServerHost:WebServerPort );

also I had something similar to _config.setOrigin("http://WebServerHost:WebServerPort");

因此,浏览器阻止SSL是原因。

so blocking SSL by browser was the cause.

这篇关于netty socket io CORS错误:Access-Control-Allow-Origin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 20:52
查看更多