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);
网友评论