Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#WPF Websocket-无法与NGINX建立握手_C#_Nginx_Spring Websocket_Websocket Sharp - Fatal编程技术网

C#WPF Websocket-无法与NGINX建立握手

C#WPF Websocket-无法与NGINX建立握手,c#,nginx,spring-websocket,websocket-sharp,C#,Nginx,Spring Websocket,Websocket Sharp,一直在使用此客户端库:[Websocket Sharp][1]来实现我的Websocket WPF客户端应用程序。 问题是,如果我使用此库的SetProxy方法在没有基本身份验证的情况下连接NGINX,则即使NGINX服务器没有配置基本身份验证,我也无法建立连接 但当我在不通过NGINX的情况下将客户端直接连接到后端服务器时,一切正常 这是我的客户代码: using (var ws = new WebSocket("ws://localhost:5555/testnginx"

一直在使用此客户端库:[Websocket Sharp][1]来实现我的Websocket WPF客户端应用程序。 问题是,如果我使用此库的SetProxy方法在没有基本身份验证的情况下连接NGINX,则即使NGINX服务器没有配置基本身份验证,我也无法建立连接

但当我在不通过NGINX的情况下将客户端直接连接到后端服务器时,一切正常

这是我的客户代码:

 using (var ws = new WebSocket("ws://localhost:5555/testnginx"))
            {
                ws.SetProxy("http://localhost:5555", null, null);
                ws.OnMessage += (sender, e) => {
                    Debug.WriteLine("Received a message: " + e.Data);
                };
这是我的NGINX设置:

location /testnginx{
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header HOST $host;
            proxy_set_header X_Forwarded_For $remote_addr;
            proxy_pass http://socketservers;
            #proxy_pass http://localhost:7777/gs-guide-websocket;
            proxy_redirect default;
            client_max_body_size 1000m; 
        } 
或者是否有其他方法可以连接到支持NGINX的springwebsocket服务器? [1] :

解决了这个问题

只需确保NGINX中的路由和stomp中配置的端点必须完全相同

比如说

NGINX路由:

location /testnginx{
}
@Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/testnginx").setAllowedOrigins("*").withSockJS();
    }
弹簧踩踏websocket端点:

location /testnginx{
}
@Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/testnginx").setAllowedOrigins("*").withSockJS();
    }