java.net.SocketTimeoutException: timeout okhttp3 post 调用接口超时问题

由于数据量很大,服务器返回的时间比较久则会报java.net.SocketTimeoutException: timeout的超时异常

需对OkHttpClient设置超时时间

OkHttpClient client = new OkHttpClient.Builder()
        .connectTimeout(60 * 1000, TimeUnit.MILLISECONDS)//连接超时
        .readTimeout(5 * 60 * 1000, TimeUnit.MILLISECONDS)//读取超时
        .writeTimeout(5 * 60 * 1000, TimeUnit.MILLISECONDS)//写入超时
        .build()
4个超时设置
api 简介 生效机制
callTimeout() 整个流程耗费的超时时间 RealCall.execute方法,设置进入
AsyncTimeout + WatchDog实现
connectTimeout() 三次握手 + SSL建立耗时 socket.connect(address, connectTimeout)
readTimeout() source读取耗时 source.timeout(readTimeout)
AsyncTimeout + WatchDog实现
rawSocket读取耗时 rawSocket.setSoTimeout(readTimeout)
writeTimeout() sink写入耗时 sink.timeout(writeTimeout)
AsyncTimeout + WatchDog实现

你可能感兴趣的:(android,android,android,studio,java)