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