首页
社区
课程
招聘
未解决 [求助]java okhttp3 发送websocket 请求报错,求指教
发表于: 2021-1-11 21:30 3174

未解决 [求助]java okhttp3 发送websocket 请求报错,求指教

2021-1-11 21:30
3174
1
2
3
4
5
6
7
OkHttpClient client = new OkHttpClient.Builder().readTimeout(9 * 10, TimeUnit.SECONDS).build();
     okhttp3.Request.Builder builder = new Request.Builder();
     UrlAndParams.addWebsocketHeaders(builder,host);
     Request request=builder.url(url).build();
     client.newWebSocket(request, this);
     System.out.println(builder.head());
     client.dispatcher().executorService().shutdown();
1
2
3
4
5
6
7
8
9
10
11
12
13
public static void addWebsocketHeaders(Request.Builder builder,String host)
{
    builder
            .addHeader("Sec-Websocket-Protocol","pbbp")
            .addHeader("Upgrade","websocket")
            .addHeader("Connection","Upgrade")
            .addHeader("Sec-WebSocket-Key","J4axdrB5EVmab8YnJ4z3bw==")
            .addHeader("Sec-WebSocket-Version","13")
            .addHeader("Accept-Encoding","gzip")
            .addHeader("host",host)
            .addHeader("User-Agent","Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Cronet Mobile/15E148 Safari/605.1");
 
}

MESSAGE: [size=17009 hex=081210bbd8d98cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d736742bb84010a962a0a145765626361…]
已经连接上流
MESSAGE: [size=17767 hex=081310d1bada8cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d736742b18a010ab5310a145765626361…]
已经连接上流
MESSAGE: [size=9623 hex=081410ce8edf8cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d736742e24a0a80170a12576562636173…]
已经连接上流
MESSAGE: [size=22762 hex=081510f0e6e38cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d736742b4b1010a89120a185765626361…]
已经连接上流
MESSAGE: [size=8774 hex=0816109ba0e98cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d73674291440aed0c0a14576562636173…]
已经连接上流
MESSAGE: [size=25632 hex=081710b081ea8cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d736742eac7010a90450a145765626361…]
已经连接上流
MESSAGE: [size=6491 hex=081810f2e0ee8cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d736742a6320ad20c0a14576562636173…]
已经连接上流
MESSAGE: [size=18263 hex=081910ddb5f38cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d736742a18e010a8d440a195765626361…]
已经连接上流
MESSAGE: [size=18341 hex=081a10b495f48cc5ffcd8cb90118b84520082a150a0d636f6d70726573735f7479706512046e6f6e65320270623a036d736742ef8e010aa31c0a145765626361…]
java.io.EOFException
at okio.RealBufferedSource.require(RealBufferedSource.kt:199)
at okio.RealBufferedSource.readByte(RealBufferedSource.kt:209)
at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:117)
at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:101)
at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:273)
at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:213)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

 

链接上了然后报错,不知原因,求指教


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2021-1-11 21:30 被Erlösung编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 4797
活跃值: (48)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
https://www.cnblogs.com/firstdream/p/9591126.html  看看是不是这个原因
2021-1-13 09:56
0
游客
登录 | 注册 方可回帖
返回
//