本文整理汇总了Java中org.apache.commons.httpclient.HttpClient.setHostConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClient.setHostConfiguration方法的具体用法?Java HttpClient.setHostConfiguration怎么用?Java HttpClient.setHostConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.HttpClient
的用法示例。
在下文中一共展示了HttpClient.setHostConfiguration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BitlyUrlShortenerImpl
import org.apache.commons.httpclient.HttpClient; //导入方法依赖的package包/类
public BitlyUrlShortenerImpl()
{
httpClient = new HttpClient();
httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setHost("api-ssl.bitly.com", 443, Protocol.getProtocol("https"));
httpClient.setHostConfiguration(hostConfiguration);
}
示例2: getHttpsClient
import org.apache.commons.httpclient.HttpClient; //导入方法依赖的package包/类
protected HttpClient getHttpsClient(String httpsHost, int httpsPort)
{
// Configure a custom SSL socket factory that will enforce mutual authentication
HttpClient httpClient = constructHttpClient();
HttpHostFactory hostFactory = new HttpHostFactory(new Protocol("https", sslSocketFactory, httpsPort));
httpClient.setHostConfiguration(new HostConfigurationWithHostFactory(hostFactory));
httpClient.getHostConfiguration().setHost(httpsHost, httpsPort, "https");
return httpClient;
}
示例3: buildClient
import org.apache.commons.httpclient.HttpClient; //导入方法依赖的package包/类
/**
* Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
* been created.
*
* @return the created client.
*/
public HttpClient buildClient() {
if (httpsProtocolSocketFactory != null) {
Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443));
}
HttpClientParams clientParams = new HttpClientParams();
clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
clientParams.setContentCharset(getContentCharSet());
clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
connectionRetryAttempts, false));
HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams();
connMgrParams.setConnectionTimeout(getConnectionTimeout());
connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost());
connMgrParams.setMaxTotalConnections(getMaxTotalConnections());
connMgrParams.setReceiveBufferSize(getReceiveBufferSize());
connMgrParams.setSendBufferSize(getSendBufferSize());
connMgrParams.setTcpNoDelay(isTcpNoDelay());
MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
connMgr.setParams(connMgrParams);
HttpClient httpClient = new HttpClient(clientParams, connMgr);
if (proxyHost != null) {
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setProxy(proxyHost, proxyPort);
httpClient.setHostConfiguration(hostConfig);
if (proxyUsername != null) {
AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
proxyPassword);
httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
}
}
return httpClient;
}