本文整理匯總了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;
}