本文整理汇总了Java中ch.boye.httpclientandroidlib.client.config.RequestConfig类的典型用法代码示例。如果您正苦于以下问题:Java RequestConfig类的具体用法?Java RequestConfig怎么用?Java RequestConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestConfig类属于ch.boye.httpclientandroidlib.client.config包,在下文中一共展示了RequestConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
if (!request.containsHeader(HTTP.EXPECT_DIRECTIVE)) {
if (request instanceof HttpEntityEnclosingRequest) {
final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
final HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
// Do not send the expect header if request body is known to be empty
if (entity != null
&& entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final RequestConfig config = clientContext.getRequestConfig();
if (config.isExpectContinueEnabled()) {
request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
}
}
}
}
}
示例2: ProxyClient
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
/**
* @since 4.3
*/
public ProxyClient(
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
final ConnectionConfig connectionConfig,
final RequestConfig requestConfig) {
super();
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
this.httpProcessor = new ImmutableHttpProcessor(
new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
this.requestExec = new HttpRequestExecutor();
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
this.authenticator = new HttpAuthenticator();
this.proxyAuthState = new AuthState();
this.authSchemeRegistry = new AuthSchemeRegistry();
this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory());
/* SPNegoSchemeFactory removed by HttpClient for Android script. */
/* KerberosSchemeFactory removed by HttpClient for Android script. */
this.reuseStrategy = new DefaultConnectionReuseStrategy();
}
示例3: InternalHttpClient
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public InternalHttpClient(
final ClientExecChain execChain,
final HttpClientConnectionManager connManager,
final HttpRoutePlanner routePlanner,
final Lookup<CookieSpecProvider> cookieSpecRegistry,
final Lookup<AuthSchemeProvider> authSchemeRegistry,
final CookieStore cookieStore,
final CredentialsProvider credentialsProvider,
final RequestConfig defaultConfig,
final List<Closeable> closeables) {
super();
Args.notNull(execChain, "HTTP client exec chain");
Args.notNull(connManager, "HTTP connection manager");
Args.notNull(routePlanner, "HTTP route planner");
this.execChain = execChain;
this.connManager = connManager;
this.routePlanner = routePlanner;
this.cookieSpecRegistry = cookieSpecRegistry;
this.authSchemeRegistry = authSchemeRegistry;
this.cookieStore = cookieStore;
this.credentialsProvider = credentialsProvider;
this.defaultConfig = defaultConfig;
this.closeables = closeables;
}
示例4: getRequestConfig
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static RequestConfig getRequestConfig(final HttpParams params) {
return RequestConfig.custom()
.setSocketTimeout(params.getIntParameter(
CoreConnectionPNames.SO_TIMEOUT, 0))
.setStaleConnectionCheckEnabled(params.getBooleanParameter(
CoreConnectionPNames.STALE_CONNECTION_CHECK, true))
.setConnectTimeout(params.getIntParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, 0))
.setExpectContinueEnabled(params.getBooleanParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, false))
.setProxy((HttpHost) params.getParameter(
ConnRoutePNames.DEFAULT_PROXY))
.setLocalAddress((InetAddress) params.getParameter(
ConnRoutePNames.LOCAL_ADDRESS))
.setProxyPreferredAuthSchemes((Collection<String>) params.getParameter(
AuthPNames.PROXY_AUTH_PREF))
.setTargetPreferredAuthSchemes((Collection<String>) params.getParameter(
AuthPNames.TARGET_AUTH_PREF))
.setAuthenticationEnabled(params.getBooleanParameter(
ClientPNames.HANDLE_AUTHENTICATION, true))
.setCircularRedirectsAllowed(params.getBooleanParameter(
ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false))
.setConnectionRequestTimeout((int) params.getLongParameter(
ClientPNames.CONN_MANAGER_TIMEOUT, 0))
.setCookieSpec((String) params.getParameter(
ClientPNames.COOKIE_POLICY))
.setMaxRedirects(params.getIntParameter(
ClientPNames.MAX_REDIRECTS, 50))
.setRedirectsEnabled(params.getBooleanParameter(
ClientPNames.HANDLE_REDIRECTS, true))
.setRelativeRedirectsAllowed(!params.getBooleanParameter(
ClientPNames.REJECT_RELATIVE_REDIRECT, false))
.build();
}
示例5: doExecute
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
@Override
protected CloseableHttpResponse doExecute(
final HttpHost target,
final HttpRequest request,
final HttpContext context) throws IOException, ClientProtocolException {
Args.notNull(target, "Target host");
Args.notNull(request, "HTTP request");
HttpExecutionAware execAware = null;
if (request instanceof HttpExecutionAware) {
execAware = (HttpExecutionAware) request;
}
try {
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
final HttpClientContext localcontext = HttpClientContext.adapt(
context != null ? context : new BasicHttpContext());
final HttpRoute route = new HttpRoute(target);
RequestConfig config = null;
if (request instanceof Configurable) {
config = ((Configurable) request).getConfig();
}
if (config != null) {
localcontext.setRequestConfig(config);
}
return this.requestExecutor.execute(route, wrapper, localcontext, execAware);
} catch (final HttpException httpException) {
throw new ClientProtocolException(httpException);
}
}
示例6: doExecute
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
@Override
protected CloseableHttpResponse doExecute(
final HttpHost target,
final HttpRequest request,
final HttpContext context) throws IOException, ClientProtocolException {
Args.notNull(request, "HTTP request");
HttpExecutionAware execAware = null;
if (request instanceof HttpExecutionAware) {
execAware = (HttpExecutionAware) request;
}
try {
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
final HttpClientContext localcontext = HttpClientContext.adapt(
context != null ? context : new BasicHttpContext());
RequestConfig config = null;
if (request instanceof Configurable) {
config = ((Configurable) request).getConfig();
}
if (config == null) {
final HttpParams params = request.getParams();
if (params instanceof HttpParamsNames) {
if (!((HttpParamsNames) params).getNames().isEmpty()) {
config = HttpClientParamConfig.getRequestConfig(params);
}
} else {
config = HttpClientParamConfig.getRequestConfig(params);
}
}
if (config != null) {
localcontext.setRequestConfig(config);
}
setupContext(localcontext);
final HttpRoute route = determineRoute(target, wrapper, localcontext);
return this.execChain.execute(route, wrapper, localcontext, execAware);
} catch (final HttpException httpException) {
throw new ClientProtocolException(httpException);
}
}
示例7: ApiEngine
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public ApiEngine(KeyStore keystore, File file, int k, int l, String userAgent) {
final HttpClientBuilder httpclientbuilder = HttpClients.custom();
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
requestConfigBuilder.setConnectionRequestTimeout(k);
requestConfigBuilder.setSocketTimeout(l);
requestConfigBuilder.setCookieSpec("best-match");
httpclientbuilder.setDefaultRequestConfig(requestConfigBuilder.build());
httpclientbuilder.setUserAgent(userAgent);
cookieStore = null;
if (file != null && file.exists() && file.isDirectory()) {
File cookieStoreFile = new File(file, "cookie.store");
if (cookieStoreFile.exists() && cookieStoreFile.canRead()) {
try {
ObjectInputStream is = new ObjectInputStream(new FileInputStream(cookieStoreFile));
cookieStore = (BasicCookieStore) is.readObject();
is.close();
} catch (Exception e) {
Log.e(Config.TAG, "Cookie file can not be read", e);
cookieStore = null;
}
}
}
if (cookieStore == null) {
cookieStore = new BasicCookieStore();
}
httpclientbuilder.setDefaultCookieStore(cookieStore);
httpClient = httpclientbuilder.build();
}
示例8: needAuthentication
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
private boolean needAuthentication(
final AuthState targetAuthState,
final AuthState proxyAuthState,
final HttpRoute route,
final HttpResponse response,
final HttpClientContext context) {
final RequestConfig config = context.getRequestConfig();
if (config.isAuthenticationEnabled()) {
HttpHost target = context.getTargetHost();
if (target == null) {
target = route.getTargetHost();
}
if (target.getPort() < 0) {
target = new HttpHost(
target.getHostName(),
route.getTargetHost().getPort(),
target.getSchemeName());
}
final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(
target, response, this.targetAuthStrategy, targetAuthState, context);
HttpHost proxy = route.getProxyHost();
// if proxy is not set use target host instead
if (proxy == null) {
proxy = route.getTargetHost();
}
final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(
proxy, response, this.proxyAuthStrategy, proxyAuthState, context);
if (targetAuthRequested) {
return this.authenticator.handleAuthChallenge(target, response,
this.targetAuthStrategy, targetAuthState, context);
}
if (proxyAuthRequested) {
return this.authenticator.handleAuthChallenge(proxy, response,
this.proxyAuthStrategy, proxyAuthState, context);
}
}
return false;
}
示例9: determineRoute
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public HttpRoute determineRoute(
final HttpHost host,
final HttpRequest request,
final HttpContext context) throws HttpException {
Args.notNull(request, "Request");
if (host == null) {
throw new ProtocolException("Target host is not specified");
}
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final RequestConfig config = clientContext.getRequestConfig();
final InetAddress local = config.getLocalAddress();
HttpHost proxy = config.getProxy();
if (proxy == null) {
proxy = determineProxy(host, request, context);
}
final HttpHost target;
if (host.getPort() <= 0) {
try {
target = new HttpHost(
host.getHostName(),
this.schemePortResolver.resolve(host),
host.getSchemeName());
} catch (final UnsupportedSchemeException ex) {
throw new HttpException(ex.getMessage());
}
} else {
target = host;
}
final boolean secure = target.getSchemeName().equalsIgnoreCase("https");
if (proxy == null) {
return new HttpRoute(target, local, secure);
} else {
return new HttpRoute(target, local, proxy, secure);
}
}
示例10: getRequestConfig
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public RequestConfig getRequestConfig() {
final RequestConfig config = getAttribute(REQUEST_CONFIG, RequestConfig.class);
return config != null ? config : RequestConfig.DEFAULT;
}
示例11: setRequestConfig
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public void setRequestConfig(final RequestConfig config) {
setAttribute(REQUEST_CONFIG, config);
}
示例12: getConfig
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public RequestConfig getConfig() {
return config;
}
示例13: setConfig
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public void setConfig(final RequestConfig config) {
this.config = config;
}
示例14: setConfig
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
public RequestBuilder setConfig(final RequestConfig config) {
this.config = config;
return this;
}
示例15: getPreferredAuthSchemes
import ch.boye.httpclientandroidlib.client.config.RequestConfig; //导入依赖的package包/类
@Override
Collection<String> getPreferredAuthSchemes(final RequestConfig config) {
return config.getProxyPreferredAuthSchemes();
}