Created
August 7, 2014 08:09
-
-
Save tbruyelle/0729aef4df2c11b21fdf to your computer and use it in GitHub Desktop.
Volley & OkHttp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.comalia.gesicamobile.manager.net; | |
import com.android.volley.toolbox.HurlStack; | |
import com.comalia.gesicamobile.manager.util.NukeSSLCerts; | |
import com.squareup.okhttp.OkHttpClient; | |
import com.squareup.okhttp.OkUrlFactory; | |
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import javax.net.ssl.HostnameVerifier; | |
import javax.net.ssl.SSLSession; | |
/** | |
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation which | |
* uses OkHttp as its transport. | |
*/ | |
public class OkHttpStack extends HurlStack { | |
private final OkUrlFactory mFactory; | |
public OkHttpStack() { | |
this(new OkHttpClient()); | |
} | |
public OkHttpStack(OkHttpClient client) { | |
if (client == null) { | |
throw new NullPointerException("Client must not be null."); | |
} | |
client.setSslSocketFactory(NukeSSLCerts.getSSLSocketFactory()); | |
client.setHostnameVerifier(new HostnameVerifier() { | |
@Override | |
public boolean verify(String hostname, SSLSession session) { | |
return true; | |
} | |
}); | |
mFactory = new OkUrlFactory(client); | |
} | |
@Override | |
protected HttpURLConnection createConnection(URL url) throws IOException { | |
return mFactory.open(url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment