本文整理匯總了Java中org.apache.http.client.params.HttpClientParams.setCookiePolicy方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientParams.setCookiePolicy方法的具體用法?Java HttpClientParams.setCookiePolicy怎麽用?Java HttpClientParams.setCookiePolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.params.HttpClientParams
的用法示例。
在下文中一共展示了HttpClientParams.setCookiePolicy方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ConnectionHelper
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
private ConnectionHelper() {
HttpParams httpParams = new BasicHttpParams();
ConnManagerParams.setMaxTotalConnections(httpParams,
MAX_TOTAL_CONNECTIONS);
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(
MAX_CONNECTIONS_PER_HOST);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(httpParams, false);
SchemeRegistry reg = new SchemeRegistry();
reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(),
80));
reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(),
443));
ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(
httpParams, reg);
HttpConnectionParams.setConnectionTimeout(httpParams, CON_TIME_OUT_MS);
HttpConnectionParams.setSoTimeout(httpParams, SO_TIME_OUT_MS);
HttpClientParams.setCookiePolicy(httpParams,
CookiePolicy.BROWSER_COMPATIBILITY);
httpClient = new DefaultHttpClient(connectionManager, httpParams);
}
示例2: HttpStoreClientFactory
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
public HttpStoreClientFactory(ClientConfig config) {
super(config);
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
config.getConnectionTimeout(TimeUnit.MILLISECONDS),
TimeUnit.MILLISECONDS);
mgr.setMaxTotal(config.getMaxTotalConnections());
mgr.setDefaultMaxPerRoute(config.getMaxConnectionsPerNode());
this.httpClient = new DefaultHttpClient(mgr);
HttpParams clientParams = this.httpClient.getParams();
HttpProtocolParams.setUserAgent(clientParams, VOLDEMORT_USER_AGENT);
HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
HttpConnectionParams.setConnectionTimeout(clientParams,
config.getConnectionTimeout(TimeUnit.MILLISECONDS));
HttpConnectionParams.setSoTimeout(clientParams,
config.getSocketTimeout(TimeUnit.MILLISECONDS));
HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER);
this.requestFormatFactory = new RequestFormatFactory();
}
示例3: getHttpParams
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
/**
* HTTP參數配置
* @return
*/
public BasicHttpParams getHttpParams(){
BasicHttpParams httpParams = new BasicHttpParams();
// 設置每個路由最大連接數
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(30);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);
HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
// 從連接池中取連接的超時時間,設置為1秒
ConnManagerParams.setTimeout(httpParams, mTimeout);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS));
ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
// 讀響應數據的超時時間
HttpConnectionParams.setSoTimeout(httpParams, mTimeout);
HttpConnectionParams.setConnectionTimeout(httpParams, mTimeout);
HttpConnectionParams.setTcpNoDelay(httpParams, true);
HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE);
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUserAgent(httpParams,userAgent);
//默認參數
HttpClientParams.setRedirecting(httpParams, false);
HttpClientParams.setCookiePolicy(httpParams,
CookiePolicy.BROWSER_COMPATIBILITY);
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
return httpParams;
}
示例4: getHttpClient
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
/**
*
* @param isMultiRequest
* 是否支持多線程
* @param connectionTimeout
* 建立連接超時時間(毫秒)
* @param socketTimeout
* 等待數據超時時間(毫秒)
* @return
*/
public static HttpClient getHttpClient(boolean isMultiRequest,
int connectionTimeout, int socketTimeout) {
SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
ClientConnectionManager cm = isMultiRequest ? new PoolingClientConnectionManager(
schemeRegistry) : new BasicClientConnectionManager(
schemeRegistry);
HttpParams params = isMultiRequest ? new SyncBasicHttpParams()
: new BasicHttpParams();
HttpClientParams.setCookiePolicy(params,
CookiePolicy.BROWSER_COMPATIBILITY);
HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
HttpConnectionParams.setSoTimeout(params, socketTimeout);
return new DefaultHttpClient(cm, params);
}
示例5: configure
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
/**
* Configures the various parameters of the connection manager and the HTTP
* client.
*
* @param params
* The parameter list to update.
*/
protected void configure(HttpParams params) {
ConnManagerParams.setMaxTotalConnections(params, getMaxTotalConnections());
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(getMaxConnectionsPerHost()));
// Configure other parameters
HttpClientParams.setAuthenticating(params, false);
HttpClientParams.setRedirecting(params, isFollowRedirects());
HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY);
HttpConnectionParams.setTcpNoDelay(params, getTcpNoDelay());
HttpConnectionParams.setConnectionTimeout(params, getConnectTimeout());
HttpConnectionParams.setSoTimeout(params, getSocketTimeout());
params.setIntParameter(ClientPNames.MAX_REDIRECTS, getMaxRedirects());
//-Dhttp.proxyHost=chlaubc.obs.pmi -Dhttp.proxyPort=8000 -Dhttp.nonProxyHosts=localhost|127.0.0.1|*.app.pmi
String httpProxyHost = getProxyHost();
if (httpProxyHost != null) {
if (StringUtils.isNotEmpty(getNonProxyHosts())) {
System.setProperty("http.nonProxyHosts", getNonProxyHosts());
} else {
System.getProperties().remove("http.nonProxyHosts");
}
System.setProperty("http.proxyPort", String.valueOf(getProxyPort()));
System.setProperty("http.proxyHost", httpProxyHost);
HttpHost proxy = new HttpHost(httpProxyHost, getProxyPort());
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
}
示例6: createClient
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
private static HttpClient createClient() {
ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
DEFAULT_CONNECTION_MANAGER_TIMEOUT,
TimeUnit.MILLISECONDS);
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
HttpParams clientParams = httpClient.getParams();
HttpConnectionParams.setSocketBufferSize(clientParams, 60000);
HttpConnectionParams.setTcpNoDelay(clientParams, false);
HttpProtocolParams.setUserAgent(clientParams, VOLDEMORT_USER_AGENT);
HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
// HostConfiguration hostConfig = new HostConfiguration();
// hostConfig.setHost("localhost");
HttpConnectionParams.setConnectionTimeout(clientParams, DEFAULT_CONNECTION_MANAGER_TIMEOUT);
HttpConnectionParams.setSoTimeout(clientParams, 500);
httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
connectionManager.setMaxTotal(DEFAULT_MAX_CONNECTIONS);
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_HOST_CONNECTIONS);
HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
return httpClient;
}
示例7: HttpClientWorker
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
public HttpClientWorker(String userAgent) {
super(userAgent);
httpClient = getThreadSafeClient();
HttpParams params = httpClient.getParams();
HttpProtocolParams.setUserAgent(params, userAgent);
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpClientParams.setRedirecting(params, false);
HttpConnectionParams.setConnectionTimeout(params,
SOCKET_OPERATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
HttpConnectionParams.setSocketBufferSize(params, BUFFER_SIZE);
HttpClientParams.setCookiePolicy(params, BROWSER_COMPATIBILITY);
}
示例8: post
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
public String post(HttpUrl httpUrl,Cookie[] cookies) throws Exception {
HttpClientParams.setCookiePolicy(httpclient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY);
for(Cookie cookie:cookies){
httpclient.getCookieStore().addCookie(cookie);
}
return this.post(httpUrl);
}