且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java.io.IOException:Android中的Connection上的流意外结束

更新时间:2021-11-21 22:02:23

我在使用OKHttp3时遇到了同样的问题.问题是我没有为每个请求关闭连接,而对于客户端,相同的连接可用,而对于服务器则没有,因此服务器返回错误.

I had the same problem using OKHttp3. The problem was that I didn't close the connection for each request and for the client the same connection was available and for the server not, for this reason the server returns a error.

该解决方案指示完成连接后关闭连接的每个请求.您必须在标头中添加一个标志来表明这一点.在OKHttp3中是这样的:

The solution is indicating to each request to close the connection when it is finished. You have to add a flag in the header to indicate this. In OKHttp3 is like this:

Request request = new Request.Builder()
                             .url(URL)
                             .header("Connection", "close")
                             ...