private HttpRequest buildHttpRequest(String url, String requestStr, boolean useKey) throws WxPayException { HttpRequest request = HttpRequest .post(url) .timeout(this.getConfig().getHttpTimeout()) .connectionTimeout(this.getConfig().getHttpConnectionTimeout()) .bodyText(requestStr); if (useKey) { SSLContext sslContext = this.getConfig().getSslContext(); if (null == sslContext) { sslContext = this.getConfig().initSSLContext(); } final SSLSocketHttpConnectionProvider provider = new SSLSocketHttpConnectionProvider(sslContext); request.withConnectionProvider(provider); } if (StringUtils.isNotBlank(this.getConfig().getHttpProxyHost()) && this.getConfig().getHttpProxyPort() > 0) { ProxyInfo httpProxy = new ProxyInfo(ProxyType.HTTP, this.getConfig().getHttpProxyHost(), this.getConfig().getHttpProxyPort(), this.getConfig().getHttpProxyUsername(), this.getConfig().getHttpProxyPassword()); HttpConnectionProvider provider = request.connectionProvider(); if (null == provider) { provider = new SocketHttpConnectionProvider(); } provider.useProxy(httpProxy); request.withConnectionProvider(provider); } return request; }
private HttpRequest buildHttpRequest(String url, String requestStr, boolean useKey) throws WxPayException { HttpRequest request = HttpRequest .post(url) .timeout(this.getConfig().getHttpTimeout()) .connectionTimeout(this.getConfig().getHttpConnectionTimeout()) .bodyText(requestStr); if (useKey) { SSLContext sslContext = this.getConfig().getSslContext(); if (null == sslContext) { sslContext = this.getConfig().initSSLContext(); } final SSLSocketHttpConnectionProvider provider = new SSLSocketHttpConnectionProvider(sslContext); request.withConnectionProvider(provider); } if (StringUtils.isNotBlank(this.getConfig().getHttpProxyHost()) && this.getConfig().getHttpProxyPort() > 0) { ProxyInfo httpProxy = new ProxyInfo(ProxyType.HTTP, this.getConfig().getHttpProxyHost(), this.getConfig().getHttpProxyPort(), this.getConfig().getHttpProxyUsername(), this.getConfig().getHttpProxyPassword()); HttpConnectionProvider provider = request.connectionProvider(); if (null == provider) { provider = new SocketHttpConnectionProvider(); } provider.useProxy(httpProxy); request.withConnectionProvider(provider); } return request; }