且构网

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

java.io.IOException:连接上的流意外结束?

更新时间:2021-11-21 22:01:41

(在我看来)请尝试以下可能的解决方案:

Please try the potential solutions (in my opinion) below:

1-尝试如下使用retryOnConnectionFailure(true):

OkHttpClient client = new OkHttpClient.Builder()
    .retryOnConnectionFailure(true)
    .build();

2-尝试添加:request.addHeader("Connection","close")(大多数情况下,这是解决方案,尊重Kartik的回答.)

2- Try to add: request.addHeader("Connection","close") (most cases this is the solution, respecting to Kartik's answer.)

Request request = new Request.Builder()
                    .addHeader("Authorization", "Bearer " + apiToken)
                    .addHeader("content-type", "application/json")
                    .addHeader("Connection","close")
                    .url(uri)
                    .build();

3-请增加服务器的响应时间(将其设置为尽可能高的值),然后重试.

3- Please increase the response time of the server (set it as high as possible) and try again.

另请参阅: OkHTTP Websocket:Connection上的蒸汽意外终止