Retrofit SocketTimeOutException in sending multiparty or JSON data in android

前端 未结 2 1254
隐瞒了意图╮
隐瞒了意图╮ 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: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;
    }
    

提交回复
热议问题