网络请求错误

2022-05-10  本文已影响0人  独自闯天涯的码农

1、Retrofit网络请求Post
错误:连接关闭了

remote server closed the connection before sending response header

原因:connectTimeout时间过短超时关闭了

OkHttpClient.Builder client = new OkHttpClient.Builder();
        client.addInterceptor(mHeaderInterceptor)//添加头部信息拦截器
                .addInterceptor(mLoggingInterceptor)//添加log拦截器
                .addInterceptor(changeUrlIntercept)//添加更改url拦截器
                .addInterceptor(new GzipRequestInterceptor())//添加压缩拦截器
                .cache(cache)
                .connectTimeout(REQUEST_TIME, TimeUnit.SECONDS)
                .readTimeout(REQUEST_TIME, TimeUnit.SECONDS)
                .writeTimeout(REQUEST_TIME, TimeUnit.SECONDS);
上一篇 下一篇

猜你喜欢

热点阅读