Retrofit SocketTimeOutException in sending multiparty or JSON data in android

╄→尐↘猪︶ㄣ 提交于 2019-12-03 08:15:01

I have this error a few days ago and I discovered that your solution is correct but add more time

private OkHttpClient getClient() {
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(5, TimeUnit.MINUTES);
    client.setReadTimeout(5, TimeUnit.MINUTES);
    return client;
}

For OkHttp3

 private OkHttpClient getClient() {
    OkHttpClient client = new OkHttpClient.Builder()
    .connectTimeout(5, TimeUnit.MINUTES)
    .readTimeout(5, TimeUnit.MINUTES)
    .build();
    return client;
}

For me the problem was from the server side.

I had to disable tcp_timestamp by changing sysctl configuration on the API server. Also, if you have other services working over TCP on the same machine i.e. Redis etc., you should watch out for how this affects them.

Found this from an issue on Github.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!