本文整理匯總了Java中org.apache.http.protocol.SyncBasicHttpContext類的典型用法代碼示例。如果您正苦於以下問題:Java SyncBasicHttpContext類的具體用法?Java SyncBasicHttpContext怎麽用?Java SyncBasicHttpContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SyncBasicHttpContext類屬於org.apache.http.protocol包,在下文中一共展示了SyncBasicHttpContext類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.apache.http.protocol.SyncBasicHttpContext; //導入依賴的package包/類
/** 執行網絡訪問 */
private static HttpResult execute(String url, HttpRequestBase requestBase) {
boolean isHttps = url.startsWith("https://");//判斷是否需要采用https
AbstractHttpClient httpClient = HttpClientFactory.create(isHttps);
HttpContext httpContext = new SyncBasicHttpContext(new BasicHttpContext());
HttpRequestRetryHandler retryHandler = httpClient.getHttpRequestRetryHandler();//獲取重試機製
int retryCount = 0;
boolean retry = true;
while (retry) {
try {
HttpResponse response = httpClient.execute(requestBase, httpContext);//訪問網絡
if (response != null) {
return new HttpResult(response, httpClient, requestBase);
}
} catch (Exception e) {
IOException ioException = new IOException(e.getMessage());
retry = retryHandler.retryRequest(ioException, ++retryCount, httpContext);//把錯誤異常交給重試機製,以判斷是否需要采取從事
}
}
return null;
}
示例2: execute
import org.apache.http.protocol.SyncBasicHttpContext; //導入依賴的package包/類
/** 執行網絡訪問 */
private static HttpResult execute(String url, HttpRequestBase requestBase) {
boolean isHttps = url.startsWith("https://");//判斷是否需要采用https
AbstractHttpClient httpClient = HttpClientFactory.create(isHttps);
HttpContext httpContext = new SyncBasicHttpContext(new BasicHttpContext());
HttpRequestRetryHandler retryHandler = httpClient.getHttpRequestRetryHandler();//獲取重試機製
int retryCount = 0;
boolean retry = true;
while (retry) {
try {
HttpResponse response = httpClient.execute(requestBase, httpContext);//訪問網絡
if (response != null) {
return new HttpResult(response, httpClient, requestBase);
}
} catch (Exception e) {
IOException ioException = new IOException(e.getMessage());
retry = retryHandler.retryRequest(ioException, ++retryCount, httpContext);//把錯誤異常交給重試機製,以判斷是否需要采取從事
LogUtils.e(e);
}
}
return null;
}
示例3: AsyncHttpClient
import org.apache.http.protocol.SyncBasicHttpContext; //導入依賴的package包/類
public AsyncHttpClient(SchemeRegistry schemeregistry)
{
a = 10;
b = 10000;
h = true;
BasicHttpParams basichttpparams = new BasicHttpParams();
ConnManagerParams.setTimeout(basichttpparams, b);
ConnManagerParams.setMaxConnectionsPerRoute(basichttpparams, new ConnPerRouteBean(a));
ConnManagerParams.setMaxTotalConnections(basichttpparams, 10);
HttpConnectionParams.setSoTimeout(basichttpparams, b);
HttpConnectionParams.setConnectionTimeout(basichttpparams, b);
HttpConnectionParams.setTcpNoDelay(basichttpparams, true);
HttpConnectionParams.setSocketBufferSize(basichttpparams, 8192);
HttpProtocolParams.setVersion(basichttpparams, HttpVersion.HTTP_1_1);
ThreadSafeClientConnManager threadsafeclientconnmanager = new ThreadSafeClientConnManager(basichttpparams, schemeregistry);
e = getDefaultThreadPool();
f = new WeakHashMap();
g = new HashMap();
d = new SyncBasicHttpContext(new BasicHttpContext());
c = new DefaultHttpClient(threadsafeclientconnmanager, basichttpparams);
c.addRequestInterceptor(new a(this));
c.addResponseInterceptor(new b(this));
c.addRequestInterceptor(new c(this), 0);
c.setHttpRequestRetryHandler(new z(5, 1500));
}
示例4: execute
import org.apache.http.protocol.SyncBasicHttpContext; //導入依賴的package包/類
/**
* 執行網絡訪問
*/
private static void execute(String url, HttpRequestBase requestBase, HttpCallbackListener httpCallbackListener) {
boolean isHttps = url.startsWith("https://");//判斷是否需要采用https
AbstractHttpClient httpClient = HttpClientFactory.create(isHttps);
HttpContext httpContext = new SyncBasicHttpContext(new BasicHttpContext());
HttpRequestRetryHandler retryHandler = httpClient.getHttpRequestRetryHandler();//獲取重試機製
int retryCount = 0;
boolean retry = true;
while (retry) {
try {
HttpResponse response = httpClient.execute(requestBase, httpContext);//訪問網絡
int stateCode = response.getStatusLine().getStatusCode();
// LogUtils.e(TAG, "http狀態碼:" + stateCode);
if (response != null) {
if (stateCode == HttpURLConnection.HTTP_OK){
HttpResult httpResult = new HttpResult(response, httpClient, requestBase);
String result = httpResult.getString();
if (!TextUtils.isEmpty(result)){
httpCallbackListener.onSuccess(result);
return;
} else {
throw new RuntimeException("數據為空");
}
} else {
throw new RuntimeException(HttpRequestCode.ReturnCode(stateCode));
}
}
} catch (Exception e) {
IOException ioException = new IOException(e.getMessage());
retry = retryHandler.retryRequest(ioException, ++retryCount, httpContext);//把錯誤異常交給重試機製,以判斷是否需要采取從事
LogUtils.e(TAG, "重複次數:" + retryCount + " :"+ e);
if (!retry){
httpCallbackListener.onError(e);
}
}
}
}
示例5: HttpDispatcher
import org.apache.http.protocol.SyncBasicHttpContext; //導入依賴的package包/類
HttpDispatcher(HttpHost host, HttpContext context){
this.context = new SyncBasicHttpContext(context);
this.host = new HttpHost(host);
}
示例6: DigiDocServiceAccessor
import org.apache.http.protocol.SyncBasicHttpContext; //導入依賴的package包/類
public DigiDocServiceAccessor() {
httpClient = getHttpClient();
httpContext = new SyncBasicHttpContext(null);
}
示例7: DobroNetwork
import org.apache.http.protocol.SyncBasicHttpContext; //導入依賴的package包/類
public DobroNetwork(DobroApplication context) {
BasicHttpParams httpParams = new BasicHttpParams();
ConnManagerParams.setTimeout(httpParams, 10000);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(20));
ConnManagerParams.setMaxTotalConnections(httpParams, 20);
HttpConnectionParams.setSoTimeout(httpParams, 10000);
HttpConnectionParams.setTcpNoDelay(httpParams, true);
HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUserAgent(httpParams, getUserAgent());
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
m_http_context = new SyncBasicHttpContext(new BasicHttpContext());
m_httpclient = new DefaultHttpClient(cm, httpParams);
m_cookie_store = new BasicCookieStore();
loadCookies();
m_http_context.setAttribute(ClientContext.COOKIE_STORE, m_cookie_store);
createDownloadReceiver();
File cacheDir = StorageUtils.getIndividualCacheDirectory(context);
disc_cache = new TotalSizeLimitedDiscCache(cacheDir, 30 * 1024 * 1024);
memory_cache = new UsingFreqLimitedMemoryCache(2 * 1024 * 1024);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPoolSize(5)
.threadPriority(Thread.NORM_PRIORITY - 2)
.memoryCache(memory_cache)
.discCache(disc_cache)
.imageDownloader(new HttpClientImageDownloader(context, m_httpclient))
.tasksProcessingOrder(QueueProcessingType.LIFO)
.defaultDisplayImageOptions(new DisplayImageOptions.Builder()
.cacheInMemory()
.cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Bitmap.Config.ARGB_8888)
.displayer(new SimpleBitmapDisplayer())
.build())
.enableLogging()
.build();
ImageLoader.getInstance().init(config);
}
示例8: setupHttp
import org.apache.http.protocol.SyncBasicHttpContext; //導入依賴的package包/類
private void setupHttp() {
httpContext = new SyncBasicHttpContext(new BasicHttpContext());
sHttpClient.setHttpRequestRetryHandler(new RetryHandler(
DEFAULT_MAX_RETRIES, DEFAULT_RETRY_SLEEP_TIME_MILLIS));
}