Okhttp3添加拦截器后,报错,java.io.IOException: unexpected end of stream on okhttp3.Address

在使用okhttp和retrofit访问网络的时候,今天测出来问题:

java.io.IOException: unexpected end of stream on okhttp3.Address@XXXX

后解决办法如下:

if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) {
            request = request.newBuilder()
                    .removeHeader("encryptValue")
                    .addHeader("encryptValue", key)
                    .addHeader("Connection", "close")
                    .build();
        }

增加关闭连接即可

 .addHeader("Connection", "close")

猜你喜欢

转载自blog.csdn.net/zhizhuodewo6/article/details/81110454