基于Vert.x的Java客户端对接Bittrex V3 SignalR遇ConnectionId格式错误
Let's walk through the most likely causes and fixes for that 400 error you're facing with your custom Vert.x Java client. This issue almost always ties to misencoded parameters or missing handshake requirements for the older ASP.NET SignalR protocol.
Fix ConnectionToken encoding first
TheConnectionTokenfrom the negotiate response contains special characters like+and/—these must be properly URL-encoded when you build your WebSocket connection URI. I noticed in your decoded example, the+was replaced with spaces, which is a critical mistake.
In Java, useURLEncoder.encode(connectionToken, "UTF-8")to encode the token fully before appending it to the request string. This ensures characters like+stay as%2Binstead of being interpreted as spaces.Validate connectionData formatting and encoding
TheconnectionDataparameter needs to be a strict JSON string ([{"name":"c3"}]) that's fully URL-encoded. Double-check that:- You haven't missed any brackets or quotes in the JSON
- The entire JSON string is encoded (e.g.,
"becomes%22,[becomes%5B) - The parameter name itself is
connectionData(not accidentally encoded as part of the value)
Remove manual ConnectionId from the request
Old ASP.NET SignalR generates theConnectionIdserver-side during negotiation—you don't need to pass it back in theconnectrequest! Adding it explicitly can confuse the server and trigger the format error. Stick to the required parameters:transport=webSockets,clientProtocol=2.0,connectionToken,connectionData, andtid=0.Verify WebSocket handshake headers
SignalR requires standard WebSocket handshake headers, plus some optional ones that might be enforced by Bittrex. Make sure your Vert.x client sends all of these:Upgrade: websocketConnection: UpgradeSec-WebSocket-Key: [random 16-byte value encoded in Base64]Sec-WebSocket-Version: 13- Optional but sometimes required:
X-Requested-With: XMLHttpRequest(to identify AJAX-style requests)
Cross-check with browser traffic
Since you already inspected Chrome's connection flow, do a side-by-side comparison between your client's request and the browser's:- Use Chrome's Network tab (filter for WebSocket) to capture the exact request URI and headers
- Compare every parameter's encoding—even a single missing
%or incorrect character can break the connection - Ensure your client's
Sec-WebSocket-Keyis generated correctly (it must be a random 16-byte string, not a fixed value)
Most folks resolve this error by fixing the ConnectionToken encoding or cleaning up the connectionData parameter. Start there, and you should be able to get past the ConnectionId format issue.
内容的提问来源于stack exchange,提问作者Olsson

