I found similar post on How to post HTTPS request using Retrofit? but it does't help me that much so i was wondering if some of you could help. This is my first post on SO and if you need any more information please let me know.
This is my code
public static OkHttpClient getUnsafeOkHttpClient() {
try {
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[0];
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts,
new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext
.getSocketFactory();
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setSslSocketFactory(sslSocketFactory);
okHttpClient.setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
okHttpClient.networkInterceptors().add(new Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
Request request = chain.request().newBuilder()
.header("user-agent", "Android")
.header("Basic","apikey")
.build();
return chain.proceed(request);
}
});
I know i can access https on my server with browser but when i try to do it here like
public WebServiceCaller(OnServiceFinished listener) {
final String baseUrl = "https://myserver.com/";
this.listener=listener;
final OkHttpClient client = getUnsafeOkHttpClient();
this.retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
serviceCaller = retrofit.create(APIinterface.class);
}
then it can not finish the request. As soon as i move s from https it works. So i guess my question is why is it not working and how can i fix this?
this are my dependencies
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp:okhttp:2.7.0'