java.io.IOException: unexpected end of stream on Connection in android

后端 未结 10 1085
你的背包
你的背包 2020-12-01 12:40

I have web service URL, it working fine. It gives the JSON data.

When I am using HttpURLConnection and InputStream, I am getting this erro

10条回答
  •  爱一瞬间的悲伤
    2020-12-01 13:20

    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.

    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")
                                 ...
    

提交回复
热议问题