troyzhxu / okhttps

如艺术一般优雅,像 1、2、3 一样简单,前后端通用,轻量却强大的 HTTP 客户端(同时支持 WebSocket 与 Stomp 协议)
https://ok.zhxu.cn
Apache License 2.0
487 stars 75 forks source link

WebSocket 连接异常 #53

Open q88qaz opened 2 years ago

q88qaz commented 2 years ago

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher Process: com.dppdkai.luckypandemo, PID: 10154 com.ejlchina.okhttps.internal.HttpException: WebSockt 连接异常: ws://myphp.com at com.ejlchina.okhttps.internal.WebSocketTask$MessageListener.onFailure(WebSocketTask.java:278) at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:570) at okhttp3.internal.ws.RealWebSocket$1.onResponse(RealWebSocket.java:199) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:929) Caused by: java.net.ProtocolException: Expected HTTP 101 response but was '200 OK' at okhttp3.internal.ws.RealWebSocket.checkUpgradeSuccess(RealWebSocket.java:224) at okhttp3.internal.ws.RealWebSocket$1.onResponse(RealWebSocket.java:195) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)  at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:929) 

troyzhxu commented 2 years ago

应该是连接地址不正确,正确的 websocket 连接地址在连接的时候会返回状态码 101,你这个地址它返回了 200

q88qaz commented 2 years ago

他是http协议的websocket

q88qaz commented 2 years ago

然后还带端口号

q88qaz commented 2 years ago

形如: http://test.xxxxxxxxxx.com:2120

troyzhxu commented 2 years ago

那这确实不是 WebSocket 协议,可能是 SockJS 协议

xyStephenZhou commented 1 year ago

是安卓端吗??安卓端不支持socketjs