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


Java HttpsURLConnection.setReadTimeout方法代码示例

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


在下文中一共展示了HttpsURLConnection.setReadTimeout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reSend

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * 重发
 * 
 * @param urlStr
 * @param parameters
 * @param count
 */
private static void reSend(String urlStr, String parameters, Map<String, Integer> count) throws IOException {
	if (count.get("times") == null) {
		count.put("times", 0);
	}
	int times = count.get("times");
	if (times < 5) {
		URL url = new URL(urlStr);
		HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
		conn.setDoOutput(true);
		conn.setDoInput(true);
		conn.setRequestMethod("POST");
		conn.setUseCaches(false);
		conn.setReadTimeout(3000);
		conn.setConnectTimeout(3000);

		OutputStream output = conn.getOutputStream();
		output.write(parameters.getBytes("utf-8"));
		output.flush();

		BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
		String s = null;
		StringBuilder sb = new StringBuilder();
		while ((s = reader.readLine()) != null) {
			sb.append(s);
		}
		reader.close();
		JSONObject jsonObject = JSONObject.parseObject(sb.toString());
		String errcode = jsonObject.get("errcode").toString();
		if (!errcode.equals("0")) {
			count.put("times", count.get("times") + 1);
			reSend(urlStr, parameters, count);
		}
	}
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:42,代码来源:WeiXinCompanySendMsg.java

示例2: buildSSLConn

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
public HttpURLConnection buildSSLConn(String url)throws Exception {
	SSLContext sc = SSLContext.getInstance("SSL");  
       sc.init(null, new TrustManager[]{new TrustAnyTrustManager()}, new java.security.SecureRandom());  
       URL console = new URL(url);  
       HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();  
       conn.setSSLSocketFactory(sc.getSocketFactory());  
       conn.setHostnameVerifier(new TrustAnyHostnameVerifier());  
	conn.setConnectTimeout(connectTimeOut);
	conn.setReadTimeout(readTimeOut);
	return conn;
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:12,代码来源:HttpUtil.java

示例3: createRequest

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
   * 创建Http/Https请求对象
   * @author Rocye
   * @param url 请求地址
   * @param method 请求方式:GET/POST
   * @param certPath 证书路径
   * @param certPass 证书密码
* @param useCert 是否需要证书
   * @return Https连接
   * @throws Exception 任何异常
   * @version 2017.11.14
   */
  private HttpsURLConnection createRequest(String url, String method, String certPath, String certPass, boolean useCert) throws Exception{
      URL realUrl = new URL(url);
      HttpsURLConnection connection = (HttpsURLConnection)realUrl.openConnection();

      //设置证书
if(useCert){
	KeyStore clientStore = KeyStore.getInstance("PKCS12");
	InputStream inputStream = new FileInputStream(certPath);
	clientStore.load(inputStream, certPass.toCharArray());
	KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
	kmf.init(clientStore, certPass.toCharArray());
	KeyManager[] kms = kmf.getKeyManagers();
	SSLContext sslContext = SSLContext.getInstance("TLSv1");
	sslContext.init(kms, null, new SecureRandom());
	connection.setSSLSocketFactory(sslContext.getSocketFactory());
}

      // 设置通用的请求属性
      connection.setRequestProperty("Accept", "*/*");
      connection.setRequestProperty("Connection", "Keep-Alive");
      connection.setConnectTimeout(this.connectTimeout);
      connection.setReadTimeout(this.readTimeout);
      if("POST".equals(method)){
          // 发送POST请求必须设置如下两行
          connection.setDoOutput(true);
          connection.setDoInput(true);
          connection.setUseCaches(false);   // 忽略缓存
          connection.setRequestMethod("POST");
      }
      return connection;
  }
 
开发者ID:rocye,项目名称:wx-idk,代码行数:44,代码来源:HttpsRequestTools.java

示例4: get

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * 鍙戦�丟et璇锋眰
 * @param url
 * @return
 * @throws NoSuchProviderException 
 * @throws NoSuchAlgorithmException 
 * @throws IOException 
 * @throws KeyManagementException 
 */
public static String get(String url,Boolean https) throws NoSuchAlgorithmException, NoSuchProviderException, IOException, KeyManagementException {
    StringBuffer bufferRes = null;
    TrustManager[] tm = { new MyX509TrustManager() };  
    SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");  
    sslContext.init(null, tm, new java.security.SecureRandom());  
    // 浠庝笂杩癝SLContext瀵硅薄涓緱鍒癝SLSocketFactory瀵硅薄  
    SSLSocketFactory ssf = sslContext.getSocketFactory();
    
    URL urlGet = new URL(url);
    HttpsURLConnection http = (HttpsURLConnection) urlGet.openConnection();
    // 杩炴帴瓒呮椂
    http.setConnectTimeout(25000);
    // 璇诲彇瓒呮椂 --鏈嶅姟鍣ㄥ搷搴旀瘮杈冩參锛屽澶ф椂闂�
    http.setReadTimeout(25000);
    http.setRequestMethod("GET");
    http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    http.setSSLSocketFactory(ssf);
    http.setHostnameVerifier(new Verifier());
    http.setDoOutput(true);
    http.setDoInput(true);
    http.connect();
    
    InputStream in = http.getInputStream();
    BufferedReader read = new BufferedReader(new InputStreamReader(in, DEFAULT_CHARSET));
    String valueString = null;
    bufferRes = new StringBuffer();
    while ((valueString = read.readLine()) != null){
        bufferRes.append(valueString);
    }
    in.close();
    if (http != null) {
        // 鍏抽棴杩炴帴
        http.disconnect();
    }
    return bufferRes.toString();
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:46,代码来源:HttpKit.java

示例5: post

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 *  鍙戦�丳ost璇锋眰
 * @param url
 * @param params
 * @return
 * @throws IOException 
 * @throws NoSuchProviderException 
 * @throws NoSuchAlgorithmException 
 * @throws KeyManagementException 
 */
public static String post(String url, String params,Boolean https) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
	StringBuffer bufferRes = null;
    TrustManager[] tm = { new MyX509TrustManager() };
    SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
    sslContext.init(null, tm, new java.security.SecureRandom());
    // 浠庝笂杩癝SLContext瀵硅薄涓緱鍒癝SLSocketFactory瀵硅薄  
    SSLSocketFactory ssf = sslContext.getSocketFactory();

    URL urlGet = new URL(url);
    HttpsURLConnection http = (HttpsURLConnection) urlGet.openConnection();
    // 杩炴帴瓒呮椂
    http.setConnectTimeout(50000);
    // 璇诲彇瓒呮椂 --鏈嶅姟鍣ㄥ搷搴旀瘮杈冩參锛屽澶ф椂闂�
    http.setReadTimeout(50000);
    http.setRequestMethod("POST");
    http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    http.setSSLSocketFactory(ssf);
    http.setHostnameVerifier(new Verifier());
    http.setDoOutput(true);
    http.setDoInput(true);
    http.connect();

    OutputStream out = http.getOutputStream();
    out.write(params.getBytes("UTF-8"));
    out.flush();
    out.close();

    InputStream in = http.getInputStream();
    BufferedReader read = new BufferedReader(new InputStreamReader(in, DEFAULT_CHARSET));
    String valueString = null;
    bufferRes = new StringBuffer();
    while ((valueString = read.readLine()) != null){
        bufferRes.append(valueString);
    }
    in.close();
    if (http != null) {
        // 鍏抽棴杩炴帴
        http.disconnect();
    }
    return bufferRes.toString();
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:52,代码来源:HttpKit.java

示例6: retreiveFlashesNonAsync

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
private boolean retreiveFlashesNonAsync(Context context) throws IOException, JSONException, ParseException{
    if (!serverLocation.getProtocol().equals("https")) {
        throw new SecurityException("Flashes may only be retrieved over a secure HTTPS connection!");
    }
    sendDebugNotification("Retrieving flashes from " + serverLocation, context);
    HttpsURLConnection urlConnection = (HttpsURLConnection) serverLocation.openConnection();
    urlConnection.setRequestProperty("Content-Type", "application/json");
    urlConnection.setRequestMethod("GET");
    urlConnection.setReadTimeout(150000);
    urlConnection.setConnectTimeout(15000);
    urlConnection.connect();
    if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                urlConnection.getInputStream()), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        String data = sb.toString();
        JSONObject jsonData = new JSONObject(data);
        serverName = jsonData.getString("server");
        flashes = convertJsonToFlashes(jsonData.getJSONArray("latest"));
    }
    sendDebugNotification("Flashes found: " + flashes.length, context);
    return true;
}
 
开发者ID:milesmcc,项目名称:LibreNews-Android,代码行数:28,代码来源:FlashRetreiver.java


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