當前位置: 首頁>>代碼示例>>Java>>正文


Java OkHttpClient.setReadTimeout方法代碼示例

本文整理匯總了Java中com.squareup.okhttp.OkHttpClient.setReadTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java OkHttpClient.setReadTimeout方法的具體用法?Java OkHttpClient.setReadTimeout怎麽用?Java OkHttpClient.setReadTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.okhttp.OkHttpClient的用法示例。


在下文中一共展示了OkHttpClient.setReadTimeout方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getHttpClient

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
/**
 * @param url
 * @return
 */
private OkHttpClient getHttpClient(String url) {
	Log.i(TAG, "getHttpClient  url = " + url);
	if (StringUtil.isNotEmpty(url, true) == false) {
		Log.e(TAG, "getHttpClient  StringUtil.isNotEmpty(url, true) == false >> return null;");
		return null;
	}

	OkHttpClient client = new OkHttpClient();
	client.setCookieHandler(new HttpHead());
	client.setConnectTimeout(15, TimeUnit.SECONDS);
	client.setWriteTimeout(10, TimeUnit.SECONDS);
	client.setReadTimeout(10, TimeUnit.SECONDS);
	//添加信任https證書,用於自簽名,不需要可刪除
	if (url.startsWith(StringUtil.URL_PREFIXs) && socketFactory != null) {
		client.setSslSocketFactory(socketFactory);
	}

	return client;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:HttpManager.java

示例2: getHttpClient

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
/**
 * @param url
 * @return
 */
private OkHttpClient getHttpClient(String url) {
	Log.i(TAG, "getHttpClient  url = " + url);
	if (StringUtil.isNotEmpty(url, true) == false) {
		Log.e(TAG, "getHttpClient  StringUtil.isNotEmpty(url, true) == false >> return null;");
		return null;
	}

	OkHttpClient client = new OkHttpClient();
	client.setCookieHandler(new HttpHead());
	client.setConnectTimeout(15, TimeUnit.SECONDS);
	client.setWriteTimeout(10, TimeUnit.SECONDS);
	client.setReadTimeout(10, TimeUnit.SECONDS);

	return client;
}
 
開發者ID:TommyLemon,項目名稱:APIJSON-Android-RxJava,代碼行數:20,代碼來源:HttpManager.java

示例3: connect

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
public void connect(String url) {
  try {
    mHttpClient= (OkHttpClient) Class.forName("com.squareup.okhttp.OkHttpClient").newInstance();
  } catch (Exception e) {
    isSupportWebSocket =false;
    return;
  }
  mHttpClient.setConnectTimeout(10, TimeUnit.SECONDS);
  mHttpClient.setWriteTimeout(10, TimeUnit.SECONDS);
  // Disable timeouts for read
  mHttpClient.setReadTimeout(0, TimeUnit.MINUTES);

  Request request = new Request.Builder().url(url).build();
  WebSocketCall call = WebSocketCall.create(mHttpClient, request);
  call.enqueue(this);
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:17,代碼來源:WXWebSocketManager.java

示例4: provideOkHttpClient

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
@Provides
@Singleton
OkHttpClient provideOkHttpClient() {
    OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.setConnectTimeout(60 * 1000, TimeUnit.MILLISECONDS);
    okHttpClient.setReadTimeout(60 * 1000, TimeUnit.MILLISECONDS);
    return okHttpClient;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:ApiServiceModule.java

示例5: OkHttpHelper

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
public OkHttpHelper() {

        mHttpClient = new OkHttpClient();
        mHttpClient.setConnectTimeout(10, TimeUnit.SECONDS);
        mHttpClient.setReadTimeout(10, TimeUnit.SECONDS);
        mHttpClient.setWriteTimeout(30, TimeUnit.SECONDS);
        mGson = new Gson();

        mHandler = new Handler(Looper.getMainLooper());

    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:OkHttpHelper.java

示例6: createClient

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
private OkHttpClient createClient() {
  final OkHttpClient okHttpClient = new OkHttpClient();
  okHttpClient.setReadTimeout(10000, TimeUnit.MILLISECONDS);
  okHttpClient.setConnectTimeout(15000, TimeUnit.MILLISECONDS);

  return okHttpClient;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:ApiConnection.java

示例7: defaultOkHttpClient

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
private static OkHttpClient defaultOkHttpClient() {
  OkHttpClient client = new OkHttpClient();
  client.networkInterceptors().add(new OkHttpInterceptor());
  client.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  client.setReadTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  client.setWriteTimeout(DEFAULT_WRITE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  return client;
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:9,代碼來源:WXOkHttpDispatcher.java

示例8: buildClientWithTimeout

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
private static OkHttpClient buildClientWithTimeout(int timeoutInSeconds) {
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(timeoutInSeconds, TimeUnit.SECONDS);
    client.setReadTimeout(timeoutInSeconds, TimeUnit.SECONDS);
    client.setWriteTimeout(timeoutInSeconds, TimeUnit.SECONDS);
    return client;
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:8,代碼來源:ApiFactory.java

示例9: getInstance

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
public static synchronized RemoteService getInstance() {
    if (service == null) {
        service = new RemoteService();
        mOkHttpClient = new OkHttpClient();

        //設置超時時間
        //參見:OkHttp3超時設置和超時異常捕獲
        //http://blog.csdn.net/do168/article/details/51848895
        mOkHttpClient.setConnectTimeout(10, TimeUnit.SECONDS);
        mOkHttpClient.setWriteTimeout(10, TimeUnit.SECONDS);
        mOkHttpClient.setReadTimeout(30, TimeUnit.SECONDS);
    }
    return service;
}
 
開發者ID:BaoBaoJianqiang,項目名稱:AndroidNetwork,代碼行數:15,代碼來源:RemoteService.java

示例10: createDefaultHttpClient

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
private OkHttpClient createDefaultHttpClient() {
    OkHttpClient httpClient = new OkHttpClient();
    httpClient.setConnectTimeout(10, TimeUnit.SECONDS);
    httpClient.setReadTimeout(10, TimeUnit.SECONDS);
    httpClient.setWriteTimeout(20, TimeUnit.SECONDS);
    httpClient.setConnectionPool(new ConnectionPool(20, 2 * 60 * 1000));
    return httpClient;
}
 
開發者ID:fivef,項目名稱:add_to_evernote_note,代碼行數:9,代碼來源:EvernoteClientFactory.java

示例11: okHttp2Client

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
@Bean
@ConditionalOnMissingBean
public OkHttpClient okHttp2Client() throws IOException {
    OkHttpClient okHttpClient = new OkHttpClient();

    if (properties.getCache().getMode() != OkHttpProperties.Cache.Mode.NONE) {
        okHttpClient.setCache(okHttp2Cache());
    }

    if (cookieHandler != null) {
        okHttpClient.setCookieHandler(cookieHandler);
    }

    OkHttpProperties.Timeout connectTimeout = properties.getConnectTimeout();
    if (connectTimeout != null) {
        okHttpClient.setConnectTimeout(connectTimeout.getValue(), connectTimeout.getUnit());
    }

    OkHttpProperties.Timeout readTimeout = properties.getReadTimeout();
    if (readTimeout != null) {
        okHttpClient.setReadTimeout(readTimeout.getValue(), readTimeout.getUnit());
    }

    OkHttpProperties.Timeout writeTimeout = properties.getWriteTimeout();
    if (writeTimeout != null) {
        okHttpClient.setWriteTimeout(writeTimeout.getValue(), writeTimeout.getUnit());
    }

    if (dns != null) {
        okHttpClient.setDns(dns);
    }

    okHttpClient.setFollowRedirects(properties.isFollowRedirects());
    okHttpClient.setFollowSslRedirects(properties.isFollowSslRedirects());
    okHttpClient.setRetryOnConnectionFailure(properties.isRetryOnConnectionFailure());

    if (applicationInterceptors != null && !applicationInterceptors.isEmpty()) {
        okHttpClient.interceptors().addAll(applicationInterceptors);
    }

    if (networkInterceptors != null && !networkInterceptors.isEmpty()) {
        okHttpClient.networkInterceptors().addAll(networkInterceptors);
    }

    if (configurers != null) {
        for (Configurer<OkHttpClient> configurer : configurers) {
            configurer.configure(okHttpClient);
        }
    }

    return okHttpClient;
}
 
開發者ID:freefair,項目名稱:okhttp-spring-boot,代碼行數:53,代碼來源:OkHttp2AutoConfiguration.java


注:本文中的com.squareup.okhttp.OkHttpClient.setReadTimeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。