当前位置: 首页>>代码示例>>Java>>正文


Java OkHttpClient.setWriteTimeout方法代码示例

本文整理汇总了Java中com.squareup.okhttp.OkHttpClient.setWriteTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java OkHttpClient.setWriteTimeout方法的具体用法?Java OkHttpClient.setWriteTimeout怎么用?Java OkHttpClient.setWriteTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.OkHttpClient的用法示例。


在下文中一共展示了OkHttpClient.setWriteTimeout方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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.setWriteTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。