I work with Retrofit2, when I try to access the https protocol, it starts swearing, how can I connect a certificate to it? On the Internet, the code found something like:
OkHttpClient okHttp = new OkHttpClient(); okHttp.setSslSocketFactory(getSSLConfig(contex).getSocketFactory()); Retrofit retrofit = builder.client(okHttp).build(); retrofit.create(serviceClass) I connected OkHttp but ... setSslSocketFactory did not find the setSslSocketFactory method there.
PS Connected OkHttp from:
compile 'com.squareup.okhttp3: okhttp: 3.6.0'
Sources:
Retrofit.Builder builder = new Retrofit.Builder() .baseUrl("https://site.cf") .addConverterFactory(GsonConverterFactory.create(gson)); CertificatePinner certificatePinner = new CertificatePinner.Builder().add("site.cf","sha256/key").build(); OkHttpClient client = new OkHttpClient.Builder() .certificatePinner(certificatePinner) .build(); Retrofit retrofit = builder.client(client).build(); API api = retrofit.create(API.class);