javax.net.ssl.HttpsURLConnection.setConnectTimeout()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中javax.net.ssl.HttpsURLConnection.setConnectTimeout()方法的一些代码示例,展示了HttpsURLConnection.setConnectTimeout()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpsURLConnection.setConnectTimeout()方法的具体详情如下:
包路径:javax.net.ssl.HttpsURLConnection
类名称:HttpsURLConnection
方法名:setConnectTimeout

HttpsURLConnection.setConnectTimeout介绍

暂无

代码示例

代码示例来源:origin: jmdhappy/xxpay-master

con.setDoOutput(true);
con.setUseCaches(false);
con.setConnectTimeout(30 * 1000);
con.setReadTimeout(60 * 1000);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

代码示例来源:origin: Javen205/IJPay

conn = (HttpsURLConnection) _url.openConnection();
conn.setConnectTimeout(25000);
conn.setReadTimeout(25000);
conn.setRequestMethod("POST");

代码示例来源:origin: Javen205/IJPay

conn = (HttpsURLConnection) _url.openConnection();
conn.setConnectTimeout(25000);
conn.setReadTimeout(25000);
conn.setRequestMethod("POST");

代码示例来源:origin: jmdhappy/xxpay-master

con.setDoOutput(true);
con.setUseCaches(false);
con.setConnectTimeout(10 * 1000);
con.setReadTimeout(5 * 1000);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

代码示例来源:origin: jmdhappy/xxpay-master

con.setDoOutput(true);
con.setUseCaches(false);
con.setConnectTimeout(10 * 1000);
con.setReadTimeout(5 * 1000);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

代码示例来源:origin: wildfly/wildfly

conn.setSSLSocketFactory(sslContext.getSocketFactory());
conn.setHostnameVerifier(hostnameVerifier);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setReadTimeout(CONNECTION_TIMEOUT);
conn.connect();

代码示例来源:origin: apache/nifi

@Override
  public void run() {
    try {
      final int port = ((HandleHttpRequest) runner.getProcessor()).getPort();
      final HttpsURLConnection connection = (HttpsURLConnection) new URL("https://localhost:"
          + port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").openConnection();
      connection.setSSLSocketFactory(sslContext.getSocketFactory());
      connection.setDoOutput(false);
      connection.setRequestMethod("GET");
      connection.setRequestProperty("header1", "value1");
      connection.setRequestProperty("header2", "");
      connection.setRequestProperty("header3", "apple=orange");
      connection.setConnectTimeout(3000);
      connection.setReadTimeout(3000);
      StreamUtils.copy(connection.getInputStream(), new NullOutputStream());
    } catch (final Throwable t) {
      t.printStackTrace();
      Assert.fail(t.toString());
    }
  }
});

代码示例来源:origin: chrisk44/Hijacker

try{
  HttpsURLConnection connection = (HttpsURLConnection) (new URL(WORDLISTS_LINK).openConnection());
  connection.setConnectTimeout(5000);
  connection.setReadTimeout(5000);

代码示例来源:origin: chrisk44/Hijacker

connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);

代码示例来源:origin: ihaolin/antares

/**
 * 设置连接超时,默认5s
 * @param secs 秒
 * @return this
 */
public Https connectTimeout(int secs){
  connection.setConnectTimeout(secs * 1000);
  return this;
}

代码示例来源:origin: ihaolin/common

/**
 * 设置连接超时,默认5s
 * @param secs 秒
 * @return this
 */
public Https connectTimeout(int secs){
  connection.setConnectTimeout(secs * 1000);
  return this;
}

代码示例来源:origin: me.hao0/common

/**
 * 设置连接超时,默认5s
 * @param secs 秒
 * @return this
 */
public Https connectTimeout(int secs){
  connection.setConnectTimeout(secs * 1000);
  return this;
}

代码示例来源:origin: gradle.plugin.com.rosberry.android.gradle/rawf

private void initConnection(HttpsURLConnection connection) {
  connection.setConnectTimeout(5000);
  connection.setUseCaches(false);
  connection.setDoInput(true);
}

代码示例来源:origin: vmware/admiral

private static void handleCertForHttpsThroughHttpProxyWithAuth(URL url, Proxy proxy,
    String proxyUsername, String proxyPassword, long timeout,
    SSLSocketFactory socketFactory) throws IOException {
  HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(proxy);
  connection.setSSLSocketFactory(socketFactory);
  connection.setConnectTimeout((int) (timeout < 0 ? 0 : timeout));
  if (proxyUsername != null && proxyPassword != null) {
    byte[] token = (proxyUsername + ":" + proxyPassword)
        .getBytes(StandardCharsets.UTF_8);
    connection.setRequestProperty(REQUEST_HEADER_PROXY_AUTHORIZATION,
        "Basic " + Base64.encodeBase64StringUnChunked(token));
  }
  connection.connect();
  connection.disconnect();
}

代码示例来源:origin: sakaiproject/sakai

private static HttpsURLConnection fetchConnection(String apiURL, int timeout, Proxy proxy)
throws MalformedURLException, IOException, ProtocolException {
  HttpsURLConnection connection;
  URL hostURL = new URL(apiURL);
  if (proxy == null) {
    connection = (HttpsURLConnection) hostURL.openConnection();
  } else {
    connection = (HttpsURLConnection) hostURL.openConnection(proxy);
  }
  // This actually turns into a POST since we are writing to the
  // resource body. ( You can see this in Webscarab or some other HTTP
  // interceptor.
  connection.setRequestMethod("GET"); 
  connection.setConnectTimeout(timeout);
  connection.setReadTimeout(timeout);
  connection.setDoOutput(true);
  connection.setDoInput(true);
  return connection;
}

代码示例来源:origin: adjust/android_sdk

@Override
  public void applyConnectionOptions(HttpsURLConnection connection, String clientSdk) {
    connection.setRequestProperty("Client-SDK", clientSdk);
    connection.setConnectTimeout(Constants.ONE_MINUTE);
    connection.setReadTimeout(Constants.ONE_MINUTE);
    if (userAgent != null) {
      connection.setRequestProperty("User-Agent", userAgent);
    }
  }
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private Map<Address, Address> callService() throws IOException, CertificateException {
  URL url = new URL(endpointUrl);
  HttpsURLConnection httpsConnection = (HttpsURLConnection) url.openConnection();
  httpsConnection.setRequestMethod("GET");
  httpsConnection.setConnectTimeout(connectionTimeoutInMillis);
  httpsConnection.setReadTimeout(connectionTimeoutInMillis);
  httpsConnection.setRequestProperty("Accept-Charset", "UTF-8");
  httpsConnection.connect();
  checkCertificate(httpsConnection);
  checkError(httpsConnection);
  return parseResponse(httpsConnection.getInputStream());
}

代码示例来源:origin: io.takari/jdkget

public static JdkReleases readFromGithub() throws IOException {
 HttpsURLConnection conn = (HttpsURLConnection) new URL(REMOTE_XML).openConnection();
 conn.setAllowUserInteraction(false);
 conn.setDoInput(true);
 conn.setDoOutput(false);
 conn.setUseCaches(true);
 conn.setRequestMethod("GET");
 conn.setConnectTimeout(TIMEOUT_VALUE);
 conn.setReadTimeout(TIMEOUT_VALUE);
 conn.connect();
 return read(conn.getInputStream());
}

代码示例来源:origin: ihaolin/antares

private void prepareRequest() {
  connection.setDoInput(true);
  connection.setDoOutput(true);
  connection.setConnectTimeout(connectTimeout);
  connection.setReadTimeout(readTimeout);
  header("Accept-Charset", acceptCharset);
  header("Connection", connectType);
  if (gzip){
    header("Accept-Encoding", "gzip, deflate");
  }
  if (!Strings.isNullOrEmpty(contentType)){
    header("Content-Type", connectType);
  }
  if (!Strings.isNullOrEmpty(acceptType)){
    header("Accept", acceptType);
  }
  if (!Strings.isNullOrEmpty(body)){
    header("Content-Length", String.valueOf(body.length()));
  }
}

代码示例来源:origin: guardianproject/NetCipher

@Test
public void testCannotConnectHttps() throws MalformedURLException, KeyManagementException {
  // TODO test connecting to http://
  // TODO test connecting to non-HTTPS port
  try {
    HttpsURLConnection https = NetCipher.getHttpsURLConnection(new URL(
        "https://127.0.0.1:63453"));
    https.setConnectTimeout(0); // blocking connect with TCP timeout
    https.connect();
    fail();
  } catch (IOException e) {
    // this should not connect
  }
}

相关文章

HttpsURLConnection类方法