总结okhttp的错误IOException: unexpected end of stream on okhttp3的解决办法

1首先在github上看到这个问题的解释:The error occurs when OkHttp try to reuse a connection that is in FIN_WAIT2 state in server, because the server keep_alive timeout is lesser than the client timeout.  于是发现了我这代码可能出问题的地方,我的okhttp设置的timeout是100,而服务器一般是60

修改后暂时没发生过这个问题。



2给okhttp添加header 拦截器中加入这个 addHeader("Connection","close")。也使用过这种方式,能解决部分问题。

注:我的项目中使用的是okhttp version 3.4.1.不知道更新以后会不会还有这种问题

猜你喜欢

转载自blog.csdn.net/mace_android/article/details/72121638