Retrofit SocketTimeOutException in sending multiparty or JSON data in android

前端 未结 2 1219
隐瞒了意图╮
隐瞒了意图╮ 2021-02-08 23:16

Facing problem in sending a Mutipart or JSON data through retrofit lib

Retrofit Interface

@Multipart
@POST(\"/api/v1/protected/updateprofile\")
void upl         


        
相关标签:
2条回答
  • 2021-02-08 23:19

    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.

    0 讨论(0)
  • 2021-02-08 23:24

    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;
    }
    
    0 讨论(0)
提交回复
热议问题