2016-11-01 2 views
2

스프링 부트를 사용하여 WebSocket 지원으로 BE 응용 프로그램을 구현했습니다. 나는 내가 다음과 같은 오류가 연결 과정 내 웹 소켓 엔드 포인트와시 연결하기 위해 SockJS를 사용 봄, SockJS - WebSocket 핸드 셰이크 중 오류 : 예기치 않은 응답 코드 400

enter image description here

하지만 모든 (위의 이미지에서 볼 수 있듯이)

error during WebSocket handshake: Unexpected response code: 400 
는 잘 작동 websocket이 열렸습니다.

지금 당장이 문제의 원인과 해결 방법을 이해하지 못합니다. 도와주세요.

업데이트]

덕분에 paweln1986 도움을 나는 SockJS lib 디렉토리와 버전 문제를 해결했지만 예기치 않은 응답 코드 400의 문제는 여전히 존재 :

enter image description here

나는 또한 앞의 nginx를 사용하여 이건 내 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의 버전이 잘못되었습니다. 당신의 /API/ 섹션에서 당신은 두 가지를 누락

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

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

관련 문제