本文整理汇总了Java中com.squareup.okhttp.OkHttpClient.setSslSocketFactory方法的典型用法代码示例。如果您正苦于以下问题:Java OkHttpClient.setSslSocketFactory方法的具体用法?Java OkHttpClient.setSslSocketFactory怎么用?Java OkHttpClient.setSslSocketFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.OkHttpClient
的用法示例。
在下文中一共展示了OkHttpClient.setSslSocketFactory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHttpClient
import com.squareup.okhttp.OkHttpClient; //导入方法依赖的package包/类
/**
* @param url
* @return
*/
private OkHttpClient getHttpClient(String url) {
Log.i(TAG, "getHttpClient url = " + url);
if (StringUtil.isNotEmpty(url, true) == false) {
Log.e(TAG, "getHttpClient StringUtil.isNotEmpty(url, true) == false >> return null;");
return null;
}
OkHttpClient client = new OkHttpClient();
client.setCookieHandler(new HttpHead());
client.setConnectTimeout(15, TimeUnit.SECONDS);
client.setWriteTimeout(10, TimeUnit.SECONDS);
client.setReadTimeout(10, TimeUnit.SECONDS);
//添加信任https证书,用于自签名,不需要可删除
if (url.startsWith(StringUtil.URL_PREFIXs) && socketFactory != null) {
client.setSslSocketFactory(socketFactory);
}
return client;
}
示例2: getUnsafeOkHttpClient
import com.squareup.okhttp.OkHttpClient; //导入方法依赖的package包/类
public OkHttpClient getUnsafeOkHttpClient() {
try {
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setSslSocketFactory(getSslSocketFactory());
okHttpClient.setHostnameVerifier(new NullHostNameVerifier());
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}