本文整理汇总了Java中org.apache.http.params.HttpConnectionParams.setSoTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java HttpConnectionParams.setSoTimeout方法的具体用法?Java HttpConnectionParams.setSoTimeout怎么用?Java HttpConnectionParams.setSoTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.params.HttpConnectionParams
的用法示例。
在下文中一共展示了HttpConnectionParams.setSoTimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSchemeRegistry
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
public static SchemeRegistry getSchemeRegistry() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
SSLSocketFactory sf = new SSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 10000);
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));
return registry;
} catch (Exception e) {
return null;
}
}
示例2: getHttpClient
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
/**
* 从可用的HttpClient池中返回一个默认10秒的HttpClient对象,该方法是同步的。
*
* @return 可用的.HttpClient对象
*/
public static synchronized HttpClient getHttpClient() {
if (null == customerHttpClient) {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpProtocolParams.setUserAgent(params,
"Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) "
+ "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");
ConnManagerParams.setTimeout(params, 10000);
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 10000);
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
customerHttpClient = new DefaultHttpClient(conMgr, params);
}
return customerHttpClient;
}
示例3: createHttpClient
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
private DefaultHttpClient createHttpClient() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params,
HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpConnectionParams.setConnectionTimeout(params,
CONNETED_TIMEOUT * 1000);
HttpConnectionParams.setSoTimeout(params, CONNETED_TIMEOUT * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ConnManagerParams.setMaxTotalConnections(params, 4);
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
schReg.register(new Scheme("https",
SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager connMgr = new ThreadSafeClientConnManager(
params, schReg);
return new DefaultHttpClient(connMgr, params);
}
示例4: performRequest
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
throws IOException, AuthFailureError {
HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders);
addHeaders(httpRequest, additionalHeaders);
addHeaders(httpRequest, request.getHeaders());
onPrepareRequest(httpRequest);
HttpParams httpParams = httpRequest.getParams();
int timeoutMs = request.getTimeoutMs();
// TODO: Reevaluate this connection timeout based on more wide-scale
// data collection and possibly different for wifi vs. 3G.
HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);
return mClient.execute(httpRequest);
}
示例5: if
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
private HttpResponse b0449щ0449щщ0449(HttpUriRequest httpUriRequest, Map map, int i) throws Exception {
URI uri = httpUriRequest.getURI();
String trim = uri.getHost() != null ? uri.getHost().trim() : "";
if (trim.length() > 0) {
httpUriRequest.setHeader("Host", trim);
}
if (map != null) {
for (Object next : map.entrySet()) {
if (((b04170417041704170417З + b0417ЗЗЗЗ0417) * b04170417041704170417З) % bЗ0417ЗЗЗ0417 != bЗЗЗЗЗ0417) {
b04170417041704170417З = 81;
bЗЗЗЗЗ0417 = 31;
}
Entry entry = (Entry) next;
httpUriRequest.setHeader((String) entry.getKey(), (String) entry.getValue());
}
}
Header[] allHeaders = httpUriRequest.getAllHeaders();
Log.d(b043D043Dнн043Dн, "request URI [" + httpUriRequest.getURI() + "]");
for (Object obj : allHeaders) {
Log.d(b043D043Dнн043Dн, "request header [" + obj.toString() + "]");
}
HttpConnectionParams.setSoTimeout(this.bнн043Dн043Dн.getParams(), i);
HttpResponse execute = this.bнн043Dн043Dн.execute(httpUriRequest);
if (execute != null) {
return execute;
}
throw new RuntimeException("Null response returned.");
}
示例6: create
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
/**
* HTTPClientオブジェクトを作成.
* @param type 通信タイプ
* @param connectionTimeout タイムアウト値(ミリ秒)。0の場合はデフォルト値を利用する。
* @return 作成したHttpClientクラスインスタンス
*/
public static HttpClient create(final String type, final int connectionTimeout) {
if (TYPE_DEFAULT.equalsIgnoreCase(type)) {
return new DefaultHttpClient();
}
SSLSocketFactory sf = null;
try {
if (TYPE_INSECURE.equalsIgnoreCase(type)) {
sf = createInsecureSSLSocketFactory();
}
} catch (Exception e) {
return null;
}
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", PORTHTTPS, sf));
schemeRegistry.register(new Scheme("http", PORTHTTP, PlainSocketFactory.getSocketFactory()));
HttpParams params = new BasicHttpParams();
ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
// ClientConnectionManager cm = new
// ThreadSafeClientConnManager(schemeRegistry);
HttpClient hc = new DefaultHttpClient(cm, params);
HttpParams params2 = hc.getParams();
int timeout = TIMEOUT;
if (connectionTimeout != 0) {
timeout = connectionTimeout;
}
HttpConnectionParams.setConnectionTimeout(params2, timeout); // 接続のタイムアウト
HttpConnectionParams.setSoTimeout(params2, timeout); // データ取得のタイムアウト
return hc;
}
示例7: a
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
public static b a() {
if (b == null) {
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, true);
basicHttpParams.setBooleanParameter("http.protocol.expect-continue", false);
ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(30));
ConnManagerParams.setTimeout(basicHttpParams, 1000);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 16384);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
HttpClientParams.setRedirecting(basicHttpParams, true);
HttpClientParams.setAuthenticating(basicHttpParams, false);
HttpProtocolParams.setUserAgent(basicHttpParams, a);
try {
SocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
Scheme scheme = new Scheme(com.alipay.sdk.cons.b.a, socketFactory, WebSocket.DEFAULT_WSS_PORT);
Scheme scheme2 = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(scheme);
schemeRegistry.register(scheme2);
b = new b(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
} catch (Exception e) {
b = new b(basicHttpParams);
}
}
return b;
}
示例8: setTimeout
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
/**
* Set the connection and socket timeout. By default, 10 seconds.
*
* @param timeout the connect/socket timeout in milliseconds, at least 1 second
*/
public void setTimeout(int timeout) {
if (timeout < 1000) timeout = DEFAULT_SOCKET_TIMEOUT;
this.timeout = timeout;
final HttpParams httpParams = this.httpClient.getParams();
ConnManagerParams.setTimeout(httpParams, this.timeout);
HttpConnectionParams.setSoTimeout(httpParams, this.timeout);
HttpConnectionParams.setConnectionTimeout(httpParams, this.timeout);
}
示例9: createClientLoginHelper
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
private IClientLoginHelper createClientLoginHelper(String accountPrompt, String service) {
if (SdkLevel.getLevel() >= SdkLevel.LEVEL_ECLAIR) {
HttpClient httpClient = new DefaultHttpClient();
HttpConnectionParams.setSoTimeout(httpClient.getParams(), SERVER_TIMEOUT_MS);
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), SERVER_TIMEOUT_MS);
return new ClientLoginHelper(activity, service, accountPrompt, httpClient);
}
return null;
}
示例10: configTimeout
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
public HttpUtils configTimeout(int timeout) {
final HttpParams httpParams = this.httpClient.getParams();
ConnManagerParams.setTimeout(httpParams, timeout);
HttpConnectionParams.setSoTimeout(httpParams, timeout);
HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
return this;
}
示例11: getHttpClient
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
public DefaultHttpClient getHttpClient()
{
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
DefaultHttpClient client = new DefaultHttpClient(httpParams);
client.getParams().setParameter(
CoreProtocolPNames.HTTP_CONTENT_CHARSET, "gb2312");
return client;
}
示例12: setHttpClientParameters
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
/**
* Sets the parameters to the request
*
* @param params
* The parameters to be set
* @param the socket time out.
*/
private static void setHttpClientParameters(HttpParams params, Integer socketTimeOut) {
HttpProtocolParams
.setContentCharset(params, Constants.DEFAULT_ENCODING);
HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, socketTimeOut);
}
示例13: executeGetRequest
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
private String executeGetRequest(String url) throws IOException {
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
HttpGet method = new HttpGet(url);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
return client.execute(method, responseHandler);
} finally {
client.getConnectionManager().shutdown();
}
}
示例14: getContent
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
/**
* 传入网络地址,并构造可以操作中断的HttpClientIO对象,返回字符串,此方法是同步的
*
* @param url
* @return 字符串结果
* @throws Exception
*/
public static String getContent(String url, HttpClientIO hcio) throws Exception {
StringBuilder sb = new StringBuilder();
HttpClient client = getHttpClient();
HttpParams httpParams = client.getParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 6000);
HttpConnectionParams.setSoTimeout(httpParams, 6000);
HttpResponse response = client.execute(new HttpGet(url));
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream is = entity.getContent();
// 回调
if (hcio != null) {
hcio.setInputStream(is);
hcio.setHttpEntity(entity);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "UTF-8"), 1024);
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
reader.close();
}
return sb.toString();
}
示例15: SimpleHttpClient
import org.apache.http.params.HttpConnectionParams; //导入方法依赖的package包/类
public SimpleHttpClient() {
this.client = new DefaultHttpClient(new ThreadSafeClientConnManager());
HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, 30000);
HttpConnectionParams.setSoTimeout(params, 30000);
client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
public boolean retryRequest(IOException e, int i, HttpContext httpContext) {
return false;
}
});
}