第一次使用CloseableHttpClient写网络请求,为了支持http和https写了一大堆配置,就像下面这样:
/** HttpClient 对象 */ private static CloseableHttpClient httpClient = null; /** CookieStore 对象 */ private static CookieStore cookieStore = null; /** Basic Auth 管理对象 **/ private static BasicCredentialsProvider basicCredentialsProvider = null; // Httpclient 初始化 static { // 注册访问协议相关的 Socket 工厂 Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSocketFactory()) .build(); // Http 连接池 PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(registry); poolingHttpClientConnectionManager.setDefaultSocketConfig(SocketCo