"WebSocket升级请求失败"是什么? Web套接字上下文中的异常意味着什么? [英] What does "WebSocket upgrade request failed" exception mean in a context of Web sockets?

查看:384
本文介绍了"WebSocket升级请求失败"是什么? Web套接字上下文中的异常意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试在IIS 8 Express上将WCF与NetHttpBinding一起使用时,客户端尝试连接时会在客户端抛出以下WebSocketException:

WebSocket升级请求失败.收到响应状态码"200(OK)",预期为"101(SwitchingProtocols)".

Google搜索没有帮助. >

此错误可能是什么原因?

解决方案

这表示HTTP服务器不支持该URL上的WebSocket.在WebSocket协商过程中,标准的HTTP 1.1 GET请求通过特殊的Upgrade: websocket标头发送到服务器,以使服务器知道客户端希望该连接使用WebSocket而不是HTTP.如果服务器支持WebSocket,并且请求标头有效,则要求服务器发送101答复,以使客户端知道服务器在连接期间将连接切换到WebSocket.除3xx重定向以外的任何其他答复均意味着服务器无法识别或不允许该URL上的Upgrade请求.

When trying to use WCF with NetHttpBinding on IIS 8 Express, the following WebSocketException is thrown on client side when the client attempts to connect:

WebSocket upgrade request failed. Received response status code '200 (OK)', expected: '101 (SwitchingProtocols)'.

Google Search is not helpful.

What could be the cause of this error?

解决方案

It means the HTTP server does not support WebSockets on that URL. During a WebSocket negotiation, a standard HTTP 1.1 GET request is sent to the server with a special Upgrade: websocket header to let the server know that the client wants the connection to use a WebSocket and not HTTP. If the server supports WebSockets, and the request headers are valid, the server is required to send a 101 reply to let the client know that the server is switching the connection over to a WebSocket for the duration of the connection. Any other reply other than a 3xx redirect means means the server does not recognize or allow the Upgrade request on that URL.

这篇关于"WebSocket升级请求失败"是什么? Web套接字上下文中的异常意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆