use of okhttp3.OkHttpClient.Builder in project BBS-Android by bdpqchen.
the class UpdatePasswordClient method getUnSaveBuilder.
private static OkHttpClient.Builder getUnSaveBuilder() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return builder;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of okhttp3.OkHttpClient.Builder in project BBS-Android by bdpqchen.
the class RxDoHttpClient method doUpdateAvatar.
public Observable<BaseResponse<BaseModel>> doUpdateAvatar(File file) {
if (file != null) {
//表单类型
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
RequestBody imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
//imgfile 后台接收图片流的参数名
builder.addFormDataPart("cropped", file.getName(), imageBody);
List<MultipartBody.Part> parts = builder.build().parts();
return mApi.doUpdateAvatar(getLatestAuthentication(), parts);
} else {
return null;
}
}
use of okhttp3.OkHttpClient.Builder in project WeexErosFramework by bmfe.
the class AxiosManager method createClient.
public OkHttpClient createClient(Context context, long timeout) {
CookieJarImpl cookieJar = new CookieJarImpl(new BMPersistentCookieStore(context));
OkHttpClient.Builder builder = new OkHttpClient.Builder().addInterceptor(new LoggerInterceptor("TAG")).connectTimeout(timeout == 0 ? 3000L : timeout, TimeUnit.MILLISECONDS).readTimeout(timeout == 0 ? 30000L : timeout, TimeUnit.MILLISECONDS).cookieJar(cookieJar);
if (DebugableUtil.isDebug()) {
builder.addNetworkInterceptor(new WeexOkhttp3Interceptor());
}
return builder.build();
}
use of okhttp3.OkHttpClient.Builder in project openremote by openremote.
the class TokenService method getUnsafeOkHttpClient.
private static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
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[] {};
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of okhttp3.OkHttpClient.Builder in project DevRing by LJYcoder.
the class RingModule method okHttpClient.
@Singleton
@Provides
OkHttpClient okHttpClient(Application application, OkHttpClient.Builder builder, HttpConfig httpConfig, HttpProgressInterceptor progressInterceptor) {
if (httpConfig.getConnectTimeout() > 0) {
builder.connectTimeout(httpConfig.getConnectTimeout(), TimeUnit.SECONDS);
}
if (httpConfig.isUseLog()) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(loggingInterceptor);
}
if (httpConfig.isUseCache()) {
HttpCacheInterceptor cacheInterceptor = new HttpCacheInterceptor(application, httpConfig.getCacheTimeWithNet(), httpConfig.getCacheTimeWithoutNet());
// 缓存目录
File cacheFile;
if (httpConfig.getCacheFolder() != null && httpConfig.getCacheFolder().isDirectory()) {
cacheFile = httpConfig.getCacheFolder();
} else {
cacheFile = FileUtil.getDirectory(FileUtil.getExternalCacheDir(application), "retrofit_http_cache");
}
// 大小默认20Mb
Cache cache = new Cache(cacheFile, httpConfig.getCacheSize() > 0 ? httpConfig.getCacheSize() : 1024 * 1024 * 20);
builder.addInterceptor(cacheInterceptor);
builder.addNetworkInterceptor(cacheInterceptor);
builder.cache(cache);
}
if (!CollectionUtil.isEmpty(httpConfig.getMapHeader())) {
HttpHeaderInterceptor headerInterceptor = new HttpHeaderInterceptor(httpConfig.getMapHeader());
builder.addInterceptor(headerInterceptor);
}
builder.addNetworkInterceptor(progressInterceptor);
return builder.build();
}
Aggregations