use of okhttp3.OkHttpClient in project okhttp by square.
the class CallTest method asyncCallEngineInitialized.
/** https://github.com/square/okhttp/issues/1801 */
@Test
public void asyncCallEngineInitialized() throws Exception {
OkHttpClient c = defaultClient().newBuilder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
throw new IOException();
}
}).build();
Request request = new Request.Builder().url(server.url("/")).build();
c.newCall(request).enqueue(callback);
RecordedResponse response = callback.await(request.url());
assertEquals(request, response.request);
}
use of okhttp3.OkHttpClient in project okhttp by square.
the class ClientAuthTest method missingClientAuthFailsForNeeds.
@Test
public void missingClientAuthFailsForNeeds() throws Exception {
OkHttpClient client = buildClient(null, clientIntermediateCa);
SSLSocketFactory socketFactory = buildServerSslSocketFactory(ClientAuth.NEEDS);
server.useHttps(socketFactory, false);
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
try {
call.execute();
fail();
} catch (SSLHandshakeException expected) {
} catch (SocketException expected) {
// JDK 9
}
}
use of okhttp3.OkHttpClient in project okhttp by square.
the class OkUrlFactory method open.
HttpURLConnection open(URL url, Proxy proxy) {
String protocol = url.getProtocol();
OkHttpClient copy = client.newBuilder().proxy(proxy).build();
if (protocol.equals("http"))
return new OkHttpURLConnection(url, copy, urlFilter);
if (protocol.equals("https"))
return new OkHttpsURLConnection(url, copy, urlFilter);
throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
use of okhttp3.OkHttpClient in project CloudReader by youlookwhat.
the class HttpUtils method getOkClient.
public OkHttpClient getOkClient() {
OkHttpClient client1;
client1 = getUnsafeOkHttpClient();
return client1;
}
use of okhttp3.OkHttpClient in project CloudReader by youlookwhat.
the class HttpUtils method getUnsafeOkHttpClient.
public OkHttpClient getUnsafeOkHttpClient() {
try {
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
}
} };
// Install the all-trusting trust manager
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
// Create an ssl socket factory with our all-trusting manager
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.readTimeout(20, TimeUnit.SECONDS);
okBuilder.connectTimeout(10, TimeUnit.SECONDS);
okBuilder.writeTimeout(20, TimeUnit.SECONDS);
okBuilder.addInterceptor(new HttpHeadInterceptor());
okBuilder.addInterceptor(getInterceptor());
okBuilder.sslSocketFactory(sslSocketFactory);
okBuilder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Log.d("HttpUtils", "==come");
return true;
}
});
return okBuilder.build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations