Android Retrofit2 + Ok Http3 Why We Use It Together

Asked 2 years ago, Updated 2 years ago, 73 views

Why are we using Retrofit2 + OkHttp3 together?

I heard from someone that they use it together because of encryption.

Is it right to tie it together because it's encryption?

android retrofit2

2022-09-21 14:02

1 Answers

Encryption can be one of the reasons, and, to be exact, it's easy to touch with the options in the okhttp client.

Below is the code I used, which monitors all activities in which the api communicates through the network interceptor to the okhttp client, and uses a setting that stops when the api call is prolonged due to the connection timeout.

These features and encryption can't be configured only on okhttp clients. But it's true that it's comfortable because I used it often.


public static Retrofit createRetrofit() {
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .addNetworkInterceptor(new StethoInterceptor())
            .connectTimeout(CONNECT_TIMEOUT_SEC, TimeUnit.SECONDS)
            .build();
    return new Retrofit.Builder()
            .baseUrl(Constant.API.BASE)
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}


2022-09-21 14:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.