All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cmonbaby.http.HttpManager Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.cmonbaby.http;

import com.cmonbaby.http.https.HttpsUtils;

import java.io.InputStream;

import javax.net.ssl.HostnameVerifier;

import okhttp3.Interceptor;

/**
 * 

Author: Simon *

QO: 8950764 *

Email: [email protected] *

WebSize: https://www.cmonbaby.com *

Version: 1.0.0 *

Date: 2020/12/28 *

Description: 框架入口,初始化等事项 */ public class HttpManager { /** * 获得请求BaseUrl * * @return 获得请求BaseUrl */ public static String BaseUrl() { return Operation.baseUrl; } /** * 是否显示HttpLoggingInterceptor打印 * * @return boolean */ public static boolean isShowLogger() { return Operation.isShowLogger; } // 添加hostName验证器 public static HostnameVerifier hostName() { return Operation.verifier; } // 添加Https证书验证 public static HttpsUtils.SSLParams sslSocketFactory() { return Operation.sslParams; } // 添加自定义请求头 public static Interceptor interceptor() { return Operation.interceptor; } public static class Operation { private static boolean isShowLogger; private static String baseUrl; private static HostnameVerifier verifier; private static HttpsUtils.SSLParams sslParams; private static Interceptor interceptor; private Operation() { } /** * 设置HttpLoggingInterceptor是否显示打印 */ public static void setShowLogger(boolean isShowLogger) { Operation.isShowLogger = isShowLogger; } /** * 设置请求BaseUrl **/ public static void setBaseUrl(String baseUrl) { Operation.baseUrl = baseUrl; } /** * 设置HostName验证器 **/ public static void setHostName(HostnameVerifier verifier) { Operation.verifier = verifier; } /** * 设置Https证书验证 **/ public static void setSslSocketFactory(InputStream[] certificates, InputStream bksFile, String password) { Operation.sslParams = HttpsUtils.getSslSocketFactory(certificates, bksFile, password); } /** * 设置自定义请求头 **/ public static void setRequestHeader(Interceptor interceptor) { Operation.interceptor = interceptor; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy