当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientBuilder.setDefaultCookieStore方法代码示例

本文整理汇总了Java中org.apache.http.impl.client.HttpClientBuilder.setDefaultCookieStore方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientBuilder.setDefaultCookieStore方法的具体用法?Java HttpClientBuilder.setDefaultCookieStore怎么用?Java HttpClientBuilder.setDefaultCookieStore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.impl.client.HttpClientBuilder的用法示例。


在下文中一共展示了HttpClientBuilder.setDefaultCookieStore方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createHttpClientBuilder

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
protected HttpClientBuilder createHttpClientBuilder(SiteConfig siteConfig) {
    HttpClientBuilder httpClientBuilder = HttpClients.custom();

    httpClientBuilder.setConnectionTimeToLive(siteConfig.getConnTimeToLiveMillis(), TimeUnit.MILLISECONDS);
    httpClientBuilder.setMaxConnPerRoute(siteConfig.getMaxConnPerRoute());
    httpClientBuilder.setMaxConnTotal(siteConfig.getMaxConnTotal());
    httpClientBuilder.setUserAgent(siteConfig.getUserAgent());

    httpClientBuilder.setRetryHandler(createHttpRequestRetryHandler());
    httpClientBuilder.setRedirectStrategy(createRedirectStrategy());
    httpClientBuilder.setSSLContext(createSSLContext());
    httpClientBuilder.setSSLHostnameVerifier(createSSLHostnameVerifier());

    httpClientBuilder.setDefaultConnectionConfig(createConnectionConfig(siteConfig));
    httpClientBuilder.setDefaultSocketConfig(createSocketConfig(siteConfig));
    httpClientBuilder.setDefaultCookieSpecRegistry(createCookieSpecRegistry());
    httpClientBuilder.setDefaultCookieStore(createCookieStore());

    return httpClientBuilder;
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:21,代码来源:HttpClientFactory.java

示例2: createHttpClient

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
/**
 * 获取Http客户端连接对象
 * @param timeOut 超时时间
 * @param proxy   代理
 * @param cookie  Cookie
 * @return Http客户端连接对象
 */
public CloseableHttpClient createHttpClient(int timeOut,HttpHost proxy,BasicClientCookie cookie) {

    // 创建Http请求配置参数
    RequestConfig.Builder builder = RequestConfig.custom()
            // 获取连接超时时间
            .setConnectionRequestTimeout(timeOut)
            // 请求超时时间
            .setConnectTimeout(timeOut)
            // 响应超时时间
            .setSocketTimeout(timeOut)
            .setCookieSpec(CookieSpecs.STANDARD);

    if (proxy!=null) {
        builder.setProxy(proxy);
    }

    RequestConfig requestConfig = builder.build();

    // 创建httpClient
    HttpClientBuilder httpClientBuilder = HttpClients.custom();

    httpClientBuilder
            // 把请求相关的超时信息设置到连接客户端
            .setDefaultRequestConfig(requestConfig)
            // 把请求重试设置到连接客户端
            .setRetryHandler(new RetryHandler())
            // 配置连接池管理对象
            .setConnectionManager(connManager);

    if (cookie!=null) {
        CookieStore cookieStore = new BasicCookieStore();
        cookieStore.addCookie(cookie);
        httpClientBuilder.setDefaultCookieStore(cookieStore);
    }

    return httpClientBuilder.build();
}
 
开发者ID:fengzhizi715,项目名称:NetDiscovery,代码行数:45,代码来源:HttpManager.java

示例3: createHttpClient

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
/**
 * 获取Http客户端连接对象
 * @param timeOut 超时时间
 * @param proxy   代理
 * @param cookie  Cookie
 * @return Http客户端连接对象
 */
private CloseableHttpClient createHttpClient(int timeOut,HttpHost proxy,BasicClientCookie cookie) {

    // 创建Http请求配置参数
    RequestConfig.Builder builder = RequestConfig.custom()
            // 获取连接超时时间
            .setConnectionRequestTimeout(timeOut)
            // 请求超时时间
            .setConnectTimeout(timeOut)
            // 响应超时时间
            .setSocketTimeout(timeOut)
            .setCookieSpec(CookieSpecs.STANDARD);

    if (proxy!=null) {
        builder.setProxy(proxy);
    }

    RequestConfig requestConfig = builder.build();

    // 创建httpClient
    HttpClientBuilder httpClientBuilder = HttpClients.custom();

    httpClientBuilder
            // 把请求相关的超时信息设置到连接客户端
            .setDefaultRequestConfig(requestConfig)
            // 把请求重试设置到连接客户端
            .setRetryHandler(new RetryHandler())
            // 配置连接池管理对象
            .setConnectionManager(connManager);

    if (cookie!=null) {
        CookieStore cookieStore = new BasicCookieStore();
        cookieStore.addCookie(cookie);
        httpClientBuilder.setDefaultCookieStore(cookieStore);
    }

    return httpClientBuilder.build();
}
 
开发者ID:fengzhizi715,项目名称:PicCrawler,代码行数:45,代码来源:HttpManager.java

示例4: build

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private CloseableHttpClient build(final Consumer<HttpClientBuilder> customizeBuilder) throws IOException {
	LOGGER.debug("HTTP {} {}", request, url);
	if (httpClient != null) {
		LOGGER.debug("Existing HttpClient re-used");
		return httpClient;
	}
	if (sslsf == null) {
		sslsf = createSSLConnectionSocketFactory(null, null, false);
	}

	HttpClientBuilder builder = HttpClients.custom()
			.setRetryHandler(new StandardHttpRequestRetryHandler(3, true) {
				@Override
				public boolean retryRequest(IOException exception,
						int executionCount, HttpContext context) {
					try {
						TimeUnit.SECONDS.sleep(3);
					} catch (InterruptedException e) {
					}
					return super.retryRequest(exception, executionCount,
							context);
				}
			}).setSSLSocketFactory(sslsf);
	if (username != null) {
		CredentialsProvider credsProvider = new BasicCredentialsProvider();
		credsProvider.setCredentials(
				new AuthScope(url.getHost(), url.getPort() == -1 ? url.getDefaultPort() : url.getPort()),
				new UsernamePasswordCredentials(username, password));

		builder.setDefaultCredentialsProvider(credsProvider);
	}
	if (disableRedirect) {
		builder.disableRedirectHandling();
	}

	addPreemptiveAuthorizationHeaders();

	if (customizeBuilder != null) {
		customizeBuilder.accept(builder);
	}
	if (!cookies.isEmpty()) {
		final CookieStore cookieStore = new BasicCookieStore();
		cookies.entrySet().stream().map(x -> new BasicClientCookie(x.getKey(), x.getValue())).forEach(cookieStore::addCookie);
		builder.setDefaultCookieStore(cookieStore);
	}
	return builder.build();
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:48,代码来源:HttpClient.java


注:本文中的org.apache.http.impl.client.HttpClientBuilder.setDefaultCookieStore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。