本文整理汇总了Java中com.loopj.android.http.MySSLSocketFactory类的典型用法代码示例。如果您正苦于以下问题:Java MySSLSocketFactory类的具体用法?Java MySSLSocketFactory怎么用?Java MySSLSocketFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MySSLSocketFactory类属于com.loopj.android.http包,在下文中一共展示了MySSLSocketFactory类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUnsafeSyncHttpClient
import com.loopj.android.http.MySSLSocketFactory; //导入依赖的package包/类
@NonNull
private SyncHttpClient getUnsafeSyncHttpClient() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, KeyManagementException, UnrecoverableKeyException {
// We initialize a default Keystore
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
// We load the KeyStore
trustStore.load(null, null);
// We initialize a new SSLSocketFactory
MySSLSocketFactory socketFactory = new MySSLSocketFactory(trustStore);
// We set that all host names are allowed in the socket factory
socketFactory.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
// We initialize the Async Client
SyncHttpClient client = new SyncHttpClient();
// We set the timeout to 30 seconds
client.setTimeout(TIMEOUT);
// We set the SSL Factory
client.setSSLSocketFactory(socketFactory);
client.setEnableRedirects(true);
client.setUserAgent("Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36");
return client;
}
示例2: getSchemeRegistry
import com.loopj.android.http.MySSLSocketFactory; //导入依赖的package包/类
public static SchemeRegistry getSchemeRegistry() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 10000);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
return registry;
} catch (Exception e) {
return null;
}
}
示例3: init
import com.loopj.android.http.MySSLSocketFactory; //导入依赖的package包/类
private void init() {
asyncHttpClient = new SyncHttpClient();
asyncHttpClient.setTimeout(60 * 1000);
asyncHttpClient.setSSLSocketFactory(MySSLSocketFactory.getFixedSocketFactory());
asyncHttpClient.setCookieStore(new BasicCookieStore());//new PersistentCookieStore(context);
addHeader("Accept", "application/json;");
addHeader("Connection", "keep-alive");
}