本文整理汇总了Java中org.apache.http.params.HttpParams类的典型用法代码示例。如果您正苦于以下问题:Java HttpParams类的具体用法?Java HttpParams怎么用?Java HttpParams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpParams类属于org.apache.http.params包,在下文中一共展示了HttpParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.apache.http.params.HttpParams; //导入依赖的package包/类
public static HttpClient get() {
HttpParams httpParams = new BasicHttpParams();
ConnManagerParams.setTimeout(httpParams, 3000);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(30));
ConnManagerParams.setMaxTotalConnections(httpParams, 30);
HttpClientParams.setRedirecting(httpParams, true);
HttpProtocolParams.setUseExpectContinue(httpParams, true);
HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
HttpConnectionParams.setSoTimeout(httpParams, 2000);
HttpConnectionParams.setConnectionTimeout(httpParams, 2000);
HttpConnectionParams.setTcpNoDelay(httpParams, true);
HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTP_TAG, PlainSocketFactory.getSocketFactory(), 80));
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, sf, 443));
} catch (Exception ex) {
ex.printStackTrace();
}
return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
}
示例2: getNewHttpClient
import org.apache.http.params.HttpParams; //导入依赖的package包/类
private static HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例3: a
import org.apache.http.params.HttpParams; //导入依赖的package包/类
public static b a(String str) {
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
HttpClientParams.setRedirecting(basicHttpParams, true);
HttpClientParams.setAuthenticating(basicHttpParams, false);
HttpProtocolParams.setUserAgent(basicHttpParams, str);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme(com.alipay.sdk.cons.b.a, SSLCertificateSocketFactory.getHttpSocketFactory(30000, null), WebSocket.DEFAULT_WSS_PORT));
ClientConnectionManager threadSafeClientConnManager = new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry);
ConnManagerParams.setTimeout(basicHttpParams, 60000);
ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(10));
ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
Security.setProperty("networkaddress.cache.ttl", "-1");
HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
return new b(threadSafeClientConnManager, basicHttpParams);
}
示例4: update
import org.apache.http.params.HttpParams; //导入依赖的package包/类
public void update(Socket sock, HttpHost target,
boolean secure, HttpParams params)
throws IOException {
assertOpen();
if (target == null) {
throw new IllegalArgumentException
("Target host must not be null.");
}
if (params == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
if (sock != null) {
this.socket = sock;
bind(sock, params);
}
targetHost = target;
connSecure = secure;
}
示例5: getHttpClientInstance
import org.apache.http.params.HttpParams; //导入依赖的package包/类
public DefaultHttpClient getHttpClientInstance() {
if (this.httpClient != null) {
return this.httpClient;
}
HttpParams params = new BasicHttpParams();
params.setParameter("http.connection.timeout", CONNECTION_TIMEOUT);
params.setParameter("http.socket.timeout", SOCKET_TIMEOUT);
params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
params.setParameter("http.useragent", "Apache-HttpClient/Android");
params.setParameter("http.connection.stalecheck", Boolean.valueOf(false));
this.httpClient = new DefaultHttpClient(params);
this.httpClient.addRequestInterceptor(new GzipHttpRequestInterceptor());
this.httpClient.addResponseInterceptor(new GzipHttpResponseInterceptor());
this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
return this.httpClient;
}
示例6: getHttpClient
import org.apache.http.params.HttpParams; //导入依赖的package包/类
public synchronized static DefaultHttpClient getHttpClient() {
try {
HttpParams params = new BasicHttpParams();
// 设置一些基本参数
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
// 超时设置
// 从连接池中取连接的超时时间
ConnManagerParams.setTimeout(params, 10000); // 连接超时
HttpConnectionParams.setConnectionTimeout(params, 10000); // 请求超时
HttpConnectionParams.setSoTimeout(params, 30000);
SchemeRegistry registry = new SchemeRegistry();
Scheme sch1 = new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80);
registry.register(sch1);
// 使用线程安全的连接管理来创建HttpClient
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(
params, registry);
mHttpClient = new DefaultHttpClient(conMgr, params);
} catch (Exception e) {
e.printStackTrace();
}
return mHttpClient;
}
示例7: createSessionInputBuffer
import org.apache.http.params.HttpParams; //导入依赖的package包/类
@Override
protected SessionInputBuffer createSessionInputBuffer(
final Socket socket,
int buffersize,
final HttpParams params) throws IOException {
if (buffersize == -1) {
buffersize = 8192;
}
SessionInputBuffer inbuffer = super.createSessionInputBuffer(
socket,
buffersize,
params);
if (wireLog.isDebugEnabled()) {
inbuffer = new LoggingSessionInputBuffer(
inbuffer,
new Wire(wireLog),
HttpProtocolParams.getHttpElementCharset(params));
}
return inbuffer;
}
示例8: newInstance
import org.apache.http.params.HttpParams; //导入依赖的package包/类
public CookieSpec newInstance(final HttpParams params) {
if (params != null) {
String[] patterns = null;
Collection<?> param = (Collection<?>) params.getParameter(
CookieSpecPNames.DATE_PATTERNS);
if (param != null) {
patterns = new String[param.size()];
patterns = param.toArray(patterns);
}
boolean singleHeader = params.getBooleanParameter(
CookieSpecPNames.SINGLE_COOKIE_HEADER, false);
return new BestMatchSpec(patterns, singleHeader);
} else {
return new BestMatchSpec();
}
}
示例9: tunnelProxy
import org.apache.http.params.HttpParams; //导入依赖的package包/类
/**
* Tracks tunnelling of the connection to a chained proxy.
* The tunnel has to be established outside by sending a CONNECT
* request to the previous proxy.
*
* @param next the proxy to which the tunnel was established.
* See {@link org.apache.http.conn.ManagedClientConnection#tunnelProxy
* ManagedClientConnection.tunnelProxy}
* for details.
* @param secure <code>true</code> if the tunnel should be
* considered secure, <code>false</code> otherwise
* @param params the parameters for tunnelling the connection
*
* @throws IOException in case of a problem
*/
public void tunnelProxy(HttpHost next, boolean secure, HttpParams params)
throws IOException {
if (next == null) {
throw new IllegalArgumentException
("Next proxy must not be null.");
}
if (params == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
//@@@ check for proxy in planned route?
if ((this.tracker == null) || !this.tracker.isConnected()) {
throw new IllegalStateException("Connection not open.");
}
this.connection.update(null, next, secure, params);
this.tracker.tunnelProxy(next, secure);
}
示例10: init
import org.apache.http.params.HttpParams; //导入依赖的package包/类
/**
* Initializes this connection object with {@link SessionInputBuffer} and
* {@link SessionOutputBuffer} instances to be used for sending and
* receiving data. These session buffers can be bound to any arbitrary
* physical output medium.
* <p>
* This method will invoke {@link #createHttpResponseFactory()},
* {@link #createRequestWriter(SessionOutputBuffer, HttpParams)}
* and {@link #createResponseParser(SessionInputBuffer, HttpResponseFactory, HttpParams)}
* methods to initialize HTTP request writer and response parser for this
* connection.
*
* @param inbuffer the session input buffer.
* @param outbuffer the session output buffer.
* @param params HTTP parameters.
*/
protected void init(
final SessionInputBuffer inbuffer,
final SessionOutputBuffer outbuffer,
final HttpParams params) {
if (inbuffer == null) {
throw new IllegalArgumentException("Input session buffer may not be null");
}
if (outbuffer == null) {
throw new IllegalArgumentException("Output session buffer may not be null");
}
this.inbuffer = inbuffer;
this.outbuffer = outbuffer;
if (inbuffer instanceof EofSensor) {
this.eofSensor = (EofSensor) inbuffer;
}
this.responseParser = createResponseParser(
inbuffer,
createHttpResponseFactory(),
params);
this.requestWriter = createRequestWriter(
outbuffer, params);
this.metrics = createConnectionMetrics(
inbuffer.getMetrics(),
outbuffer.getMetrics());
}
示例11: DefaultRequestDirector
import org.apache.http.params.HttpParams; //导入依赖的package包/类
@Deprecated
public DefaultRequestDirector(
final HttpRequestExecutor requestExec,
final ClientConnectionManager conman,
final ConnectionReuseStrategy reustrat,
final ConnectionKeepAliveStrategy kastrat,
final HttpRoutePlanner rouplan,
final HttpProcessor httpProcessor,
final HttpRequestRetryHandler retryHandler,
final RedirectHandler redirectHandler,
final AuthenticationHandler targetAuthHandler,
final AuthenticationHandler proxyAuthHandler,
final UserTokenHandler userTokenHandler,
final HttpParams params) {
this(LogFactory.getLog(DefaultRequestDirector.class),
requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
new DefaultRedirectStrategyAdaptor(redirectHandler),
new AuthenticationStrategyAdaptor(targetAuthHandler),
new AuthenticationStrategyAdaptor(proxyAuthHandler),
userTokenHandler,
params);
}
示例12: setUp
import org.apache.http.params.HttpParams; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
HttpParams httpParams = new BasicHttpParams();
when(mockHttpClientFactory.create()).thenReturn(mockHttpClient);
when(mockHttpClient.getParams()).thenReturn(httpParams);
when(mockHttpClient.getConnectionManager()).thenReturn(mockClientConnectionManager);
when(mockClientConnectionManager.getSchemeRegistry()).thenReturn(mockSchemeRegistry);
}
示例13: setMaxConnections
import org.apache.http.params.HttpParams; //导入依赖的package包/类
/**
* Sets maximum limit of parallel connections
*
* @param maxConnections maximum parallel connections, must be at least 1
*/
public void setMaxConnections(int maxConnections) {
if (maxConnections < 1)
maxConnections = DEFAULT_MAX_CONNECTIONS;
this.maxConnections = maxConnections;
final HttpParams httpParams = this.httpClient.getParams();
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(this.maxConnections));
}
示例14: getNewHttpClient
import org.apache.http.params.HttpParams; //导入依赖的package包/类
public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) {
try {
SSLSocketFactory sf = new MySSLSocketFactory(keyStore);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme(b.a, sf, WebSocket.DEFAULT_WSS_PORT));
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
return new DefaultHttpClient(new ThreadSafeClientConnManager(params, registry), params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例15: ak
import org.apache.http.params.HttpParams; //导入依赖的package包/类
private ak(Context context) {
try {
dk = context.getApplicationContext();
this.cv = System.currentTimeMillis() / 1000;
this.dh = new f();
if (c.k()) {
try {
Logger.getLogger("org.apache.http.wire").setLevel(Level.FINER);
Logger.getLogger("org.apache.http.headers").setLevel(Level.FINER);
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons" +
".logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient" +
".wire", BuildConfig.BUILD_TYPE);
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache" +
".http", BuildConfig.BUILD_TYPE);
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http" +
".headers", BuildConfig.BUILD_TYPE);
} catch (Throwable th) {
}
}
HttpParams basicHttpParams = new BasicHttpParams();
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 10000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 10000);
this.dg = new DefaultHttpClient(basicHttpParams);
this.dg.setKeepAliveStrategy(new al(this));
} catch (Throwable th2) {
cx.b(th2);
}
}