{"record":{"id":"6c72b325a6269b99","repo":"dotnet/aspnetcore","slug":"error-reading-negotiateresponse","errorCode":null,"errorMessage":"Error reading NegotiateResponse","messagePattern":"Error reading NegotiateResponse","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/NegotiateResponse.java","lineNumber":86,"sourceCode":"                                this.availableTransports.add(transport);\n                            }\n                            reader.endObject();\n                        }\n                        reader.endArray();\n                        break;\n                    case \"connectionId\":\n                        this.connectionId = reader.nextString();\n                        break;\n                    default:\n                        // Skip unknown property, allows new clients to still work with old protocols\n                        reader.skipValue();\n                        break;\n                }\n            } while (reader.hasNext());\n            reader.endObject();\n            reader.close();\n        } catch (IOException ex) {\n            throw new RuntimeException(\"Error reading NegotiateResponse\", ex);\n        }\n    }\n\n    public NegotiateResponse(String url) {\n        this.finalUrl = url;\n    }\n\n    public String getConnectionId() {\n        return connectionId;\n    }\n\n    public Set<String> getAvailableTransports() {\n        return availableTransports;\n    }\n\n    public String getRedirectUrl() {\n        return redirectUrl;\n    }","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/NegotiateResponse.java#L68-L104","documentation":"Thrown when the Gson JsonReader hits an IOException while parsing the negotiate HTTP response (malformed JSON, an unexpected token type such as nextString() on a number, a truncated stream, or a network read failure mid-parse). The raw IOException is wrapped in a RuntimeException because the NegotiateResponse constructor does not declare checked exceptions.","triggerScenarios":"Server returns non-JSON or a partial body to the /negotiate POST; a field arrives as the wrong JSON type; connection drops during negotiate read; an auth redirect returns HTML instead of JSON.","commonSituations":"Connecting through a reverse proxy/gateway that strips or truncates the negotiate response; pointing at a non-SignalR endpoint; hitting a legacy ASP.NET (non-Core) server; load balancer returning an HTML error page (502/503); CORS/auth returning HTML.","solutions":["Verify the negotiate URL returns a JSON object containing connectionId/availableTransports.","Confirm you are targeting an ASP.NET Core SignalR hub, not legacy ASP.NET.","Inspect the actual negotiate response body with curl/Postman and fix any proxy truncation.","Ensure no auth redirect or error page intercepts the negotiate request."],"exampleFix":"// diagnose before fixing client code:\n// curl -i -X POST https://host/hub/negotiate  -H 'Content-Length: 0'\n// expect: {\"connectionId\":\"...\",\"availableTransports\":[...]}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Java - start() propagates the wrapped RuntimeException\nhubConnection.start().subscribe(\n    () -> { /* connected */ },\n    error -> {\n        if (error.getMessage() != null && error.getMessage().contains(\"NegotiateResponse\")) {\n            // inspect server /negotiate endpoint, proxies, auth redirects\n        }\n    });","preventionTips":["Validate the /negotiate endpoint returns JSON before wiring the client.","Confirm the target is an ASP.NET Core (not legacy ASP.NET) SignalR hub.","Make sure no auth redirect or HTML error page intercepts negotiate."],"tags":["signalr","network","negotiate","json","java"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}