2016-11-01 11 views
2

Springブートを使用してWebアプリケーションをサポートするBEアプリケーションを実装しました。すべてが正常に動作している(上記の画像で見ることができるように)、その後Spring、SockJS - WebSocketハンドシェイク中にエラーが発生しました:予期しない応答コード400

error during WebSocket handshake: Unexpected response code: 400 

enter image description here

しかし:私は私のWebSocketエンドポイントに接続し、接続プロセスの間に、私は次のエラーを取得するためにSockJSを使用しますwebsocketが開かれました。

今、私はこの問題の原因と解決方法を理解していません。助けてください。

enter image description here

私も前にnginxのを使用して:私はSockJS libにとバージョンの問題を修正しましたが、予期しない応答コード400の問題がまだ存在するpaweln1986助けを

おかげ更新

これは私のnginxの設定です:

server { 
    listen   443 ssl;   
    server_name myserver.com; 
    ssl on; 

    location /api/ {                                                            
     proxy_pass_header X-XSRF-TOKEN;                                                                                                                        
     proxy_pass  http://localhost:8081/api/;                                                                                                                    
     proxy_set_header Origin "http://localhost:8081/api/";                                                  

     proxy_set_header Host $host;                                                        
     proxy_set_header X-Real-IP $remote_addr;                                                     
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                                                
     proxy_http_version 1.1;                                                         
    }                                                                

    location /dashboard/ { 
     proxy_pass  http://localhost:8081/dashboard/; 

     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 

    location /manager { 
     proxy_pass  http://localhost:8081/manager/; 

     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    }   

    location/{ 
     root /srv/www/htdocs/myserver/; 
     index index.html index.htm; 
    } 

    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /srv/www/htdocs/; 
    }   

} 

答えて

2

SockJSのバージョンが間違っています。

On the browser side, applications can use the sockjs-client (version 1.0.x) that emulates the W3C WebSocket API

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html

あなたの/API/セクションの下に2つの事、それは、クライアントまたはサーバ側に固定してください proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; https://www.nginx.com/blog/websocket-nginx/

+0

おかげで、不足していますか? – alexanoid

+0

クライアント側。 https://github.com/sockjs/sockjs-client/releases/tag/v1.0.3 – PawelN

+0

ご協力ありがとうございます!私はSockJSのlibとのバージョンの問題を修正しましたが、予期しない応答コード400の問題はまだ存在します: – alexanoid