1007 api protocol_error ai_generated true

WebSocket close code 1007: Payload data is not consistent with the type of the endpoint's protocol

ID: api/websocket-close-1007-payload-data

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2024-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
websockets 10.0 active
ws 8.13.0 active
Spring WebSocket 6.0 active
nodejs 20.x active

Root Cause

Server received a binary frame on a text-only WebSocket endpoint, or text frame with invalid UTF-8 encoding.

generic

中文

服务器在仅文本的 WebSocket 端点上收到了二进制帧,或文本帧包含无效的 UTF-8 编码。

Official Documentation

https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code#value_1007

Workarounds

  1. 90% success Ensure the client sends text frames (opcode 0x1) instead of binary frames (opcode 0x2). In JavaScript WebSocket API, always use `ws.send('string data')` not `ws.send(new ArrayBuffer(...))`.
    Ensure the client sends text frames (opcode 0x1) instead of binary frames (opcode 0x2). In JavaScript WebSocket API, always use `ws.send('string data')` not `ws.send(new ArrayBuffer(...))`.
  2. 85% success If binary data is required, configure the server endpoint to accept binary frames (e.g., in Spring WebSocket use `extends BinaryWebSocketHandler` instead of `TextWebSocketHandler`).
    If binary data is required, configure the server endpoint to accept binary frames (e.g., in Spring WebSocket use `extends BinaryWebSocketHandler` instead of `TextWebSocketHandler`).

中文步骤

  1. 确保客户端发送文本帧(操作码 0x1)而不是二进制帧(操作码 0x2)。在 JavaScript WebSocket API 中,始终使用 `ws.send('字符串数据')`,不要使用 `ws.send(new ArrayBuffer(...))`。
  2. 如果确实需要二进制数据,请将服务器端点配置为接受二进制帧(例如,在 Spring WebSocket 中使用 `extends BinaryWebSocketHandler` 而不是 `TextWebSocketHandler`)。

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The issue is protocol-level, not a transient connection glitch. Restarting only resets state temporarily without fixing the frame type mismatch.

  2. 95% fail

    Buffer size doesn't affect frame type validation; the server still rejects binary frames on text endpoints regardless of buffer limits.