WebSocketBadStatusException:握手状态 200 OK

WebSocketBadStatusException: Handshake status 200 OK

我在握手中得到了 HTTP 200 而不是 HTTP 101。我使用这个 SignalR 客户端库 mandrewcito/signalrcore。我的 API 通过 SSL (TLS 1.2) 托管在 IIS 上。

代码

self.awakeHub = HubConnectionBuilder()\
    .with_url(self.configuration.ServiceBaseAddress + "/hubs/awake", options=
    {
        "verify_ssl": False,
        "skip_negotiation": False,
    })\
    .configure_logging(logging.DEBUG, socket_trace=True)\
    .with_automatic_reconnect({
        "type": "interval",
        "keep_alive_interval": 10,
        "intervals": [1, 3, 5, 6, 7, 87, 3]
    }).build()

self.awakeHub.on_open(lambda: print("connection opened and handshake received ready to send messages"))
self.awakeHub.on_close(lambda: print("connection closed"))
self.awakeHub.on_error(lambda data: print(f"An exception was thrown closed{data.error}"))

self.awakeHub.on("AwakeReceived_Group", lambda data: self.awakeReceived(data))

self.awakeHub.start()

HEADERS

Upgrade: websocket
Host: ***********
Origin: http://........
Sec-WebSocket-Key: rYqQacwytXMJ2roFL6AgwQ==
Sec-WebSocket-Version: 13
Connection: upgrade

2020-11-16 20:47:57,432 - websocket - DEBUG - -----------------------
2020-11-16 20:47:57,432 - websocket - DEBUG - --- response header ---
2020-11-16 20:47:57,451 - websocket - DEBUG - HTTP/1.1 200 OK
2020-11-16 20:47:57,452 - websocket - DEBUG - Content-Length: 0
2020-11-16 20:47:57,453 - websocket - DEBUG - Content-Type: application/octet-stream
2020-11-16 20:47:57,453 - websocket - DEBUG - Server: Microsoft-IIS/8.5
2020-11-16 20:47:57,454 - websocket - DEBUG - X-Powered-By: ASP.NET
2020-11-16 20:47:57,454 - websocket - DEBUG - Date: Mon, 16 Nov 2020 19:47:56 GMT
2020-11-16 20:47:57,455 - websocket - DEBUG - -----------------------

“握手状态 200 OK”是指他们使用了错误的传输类型。 “握手状态 404 未找到”是在服务器端不允许 websockets 通信时。

我必须在 IIS 中打开 websockets 功能,因为这个库只支持 websockets 传输类型。