1007
api
protocol_error
ai_generated
true
WebSocket 关闭码 1007:负载数据与端点协议类型不一致
WebSocket close code 1007: Payload data is not consistent with the type of the endpoint's protocol
ID: api/websocket-close-1007-payload-data
85%修复率
88%置信度
1证据数
2024-03-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| websockets 10.0 | active | — | — | — |
| ws 8.13.0 | active | — | — | — |
| Spring WebSocket 6.0 | active | — | — | — |
| nodejs 20.x | active | — | — | — |
根因分析
服务器在仅文本的 WebSocket 端点上收到了二进制帧,或文本帧包含无效的 UTF-8 编码。
English
Server received a binary frame on a text-only WebSocket endpoint, or text frame with invalid UTF-8 encoding.
官方文档
https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code#value_1007解决方案
-
确保客户端发送文本帧(操作码 0x1)而不是二进制帧(操作码 0x2)。在 JavaScript WebSocket API 中,始终使用 `ws.send('字符串数据')`,不要使用 `ws.send(new ArrayBuffer(...))`。 -
如果确实需要二进制数据,请将服务器端点配置为接受二进制帧(例如,在 Spring WebSocket 中使用 `extends BinaryWebSocketHandler` 而不是 `TextWebSocketHandler`)。
无效尝试
常见但无效的做法:
-
90% 失败
The issue is protocol-level, not a transient connection glitch. Restarting only resets state temporarily without fixing the frame type mismatch.
-
95% 失败
Buffer size doesn't affect frame type validation; the server still rejects binary frames on text endpoints regardless of buffer limits.