org.jsoup.Connection.validateTLSCertificates()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(488)

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

Connection.validateTLSCertificates介绍

[英]Disable/enable TLS certificates validation for HTTPS requests.

By default this is true; all connections over HTTPS perform normal validation of certificates, and will abort requests if the provided certificate does not validate.

Some servers use expired, self-generated certificates; or your JDK may not support SNI hosts. In which case, you may want to enable this setting.

Be careful and understand why you need to disable these validations.
[中]禁用/启用HTTPS请求的TLS证书验证。
默认情况下,这是正确的;HTTPS上的所有连接都执行证书的正常验证,如果提供的证书未验证,则将中止请求。
某些服务器使用过期的、自行生成的证书;或者您的JDK可能不支持SNI主机。在这种情况下,您可能需要启用此设置。
请小心并理解为什么需要禁用这些验证。

代码示例

代码示例来源:origin: ChinaSilence/any-video

public static Document getDocWithPhone(String url) {
  try {
    return Jsoup.connect(url).userAgent(UA_PHONE).timeout(TIME_OUT).ignoreContentType(true).validateTLSCertificates(false).get();
  } catch (IOException e) {
    log.error(ERROR_DESC + url);
    throw new AnyException(ERROR_DESC + url);
  }
}

代码示例来源:origin: g00glen00b/spring-samples

private Mono<Document> getDocument(String seed) {
    try {
      return Mono.just(Jsoup.connect(seed).validateTLSCertificates(false).get());
    } catch (IOException | IllegalArgumentException e) {
      logger.debug("Could not fetch from seed {}", seed, e);
      return Mono.empty();
    }
  }
}

代码示例来源:origin: AlexanderBartash/hybris-integration-intellij-idea-plugin

private Connection connect(@NotNull String url) throws NoSuchAlgorithmException, KeyManagementException {
    TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
      @Nullable
      public X509Certificate[] getAcceptedIssuers() {
        return null;
      }

      public void checkClientTrusted(@NotNull X509Certificate[] certs, @NotNull String authType) { }

      public void checkServerTrusted(@NotNull X509Certificate[] certs, @NotNull String authType) { }
    }};
    SSLContext sc = SSLContext.getInstance("TLSv1");
    sc.init(null, trustAllCerts, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(new NoopHostnameVerifier());
    return Jsoup.connect(url).validateTLSCertificates(false);
  }
}

代码示例来源:origin: senbox-org/s1tbx

private static List<String> getFileURLs(String path, final Set<String> currentList) {
    final List<String> fileList = new ArrayList<>();
    try {
      final Document doc = Jsoup.connect(path).timeout(10*1000).validateTLSCertificates(false).get();

      final Element table = doc.select("table").first();
      final Elements tbRows = table.select("tr");

      for(Element row : tbRows) {
        Elements tbCols = row.select("td");
        for(Element col : tbCols) {
          Elements elems = col.getElementsByTag("a");
          for(Element elem : elems) {
            String link = elem.text();
            if(!currentList.contains(link)) {
              fileList.add(elem.text());
            }
          }
        }
      }
    } catch (Exception e) {
      SystemUtils.LOG.warning("Unable to connect to "+path+ ": "+e.getMessage());
    }
    return fileList;
  }
}

代码示例来源:origin: senbox-org/s1tbx

private List<String> getFileURLs(String path) {
    final List<String> fileList = new ArrayList<>();
    try {
      final Document doc = Jsoup.connect(path).timeout(10*1000).validateTLSCertificates(false).get();

      final Element table = doc.select("table").first();
      final Elements tbRows = table.select("tr");

      for(Element row : tbRows) {
        Elements tbCols = row.select("td");
        for(Element col : tbCols) {
          Elements elems = col.getElementsByTag("a");
          for(Element elem : elems) {
            String link = elem.text();
            if(link.endsWith(".zip")) {
              fileList.add(elem.text());
            }
          }
        }
      }
    } catch (Exception e) {
      SystemUtils.LOG.warning("Unable to connect to "+path+ ": "+e.getMessage());
    }
    return fileList;
  }
}

代码示例来源:origin: SudaVideo/MyVideoApi

public static Document getDocWithPhone(String url) {
    try {
      return Jsoup.connect(url).userAgent(UA_PHONE).timeout(TIME_OUT).ignoreContentType(true).validateTLSCertificates(false).get();
    } catch (IOException e) {
      log.error(ERROR_DESC + url);
      throw new BizException(BizErrorCodeConstants.S0002, e);
    }
  }
}

代码示例来源:origin: Kaysoro/KaellyBot

public static Document getDocument(String url) throws IOException {
  return Jsoup.connect(url)
      .userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0")
      .referrer("http://www.google.com")
      .timeout(10000)
      .validateTLSCertificates(false)
      .get();
}

代码示例来源:origin: Kaysoro/KaellyBot

public static Connection.Response getResponse(String url) throws IOException {
    return Jsoup.connect(url)
        .userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0")
        .referrer("http://www.google.com")
        .timeout(10000)
        .validateTLSCertificates(false)
        .execute();
  }
}

代码示例来源:origin: calvinaquino/LNReader-Android

private Response connect(String url, int retry) throws IOException {
  // allow to use its keystore.
  return Jsoup.connect(url).validateTLSCertificates(!getUseAppKeystore()).timeout(getTimeout(retry)).execute();
}

代码示例来源:origin: zc-zh-001/ShadowSocks-Share

protected Connection getConnection(String url) {
  @SuppressWarnings("deprecation")
  Connection connection = Jsoup.connect(url)
      .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36")
      // .referrer("https://www.google.com/")
      .ignoreContentType(true)
      .followRedirects(true)
      .ignoreHttpErrors(true)
      .validateTLSCertificates(false)
      .timeout(TIME_OUT);
  if (isProxyEnable())
    connection.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(getProxyHost(), getProxyPort())));
  return connection;
}

代码示例来源:origin: dimtion/Shaarlier

/**
 * Helper method which create a new connection to Shaarli
 * @param url the url of the shaarli
 * @param isPost true if we create a POST request, false for a GET request
 * @return pre-made jsoupConnection
 */
private Connection createShaarliConnection(String url, boolean isPost){
  Connection jsoupConnection = Jsoup.connect(url);
  Connection.Method connectionMethod = isPost ? Connection.Method.POST : Connection.Method.GET;
  if (!"".equals(this.mBasicAuth)) {
    jsoupConnection = jsoupConnection.header("Authorization", "Basic " + this.mBasicAuth);
  }
  if (this.mCookies != null){
    jsoupConnection = jsoupConnection.cookies(this.mCookies);
  }
  return jsoupConnection
      .validateTLSCertificates(this.mValidateCert)
      .timeout(this.mTimeout)
      .followRedirects(true)
      .method(connectionMethod);
}

代码示例来源:origin: Kaysoro/KaellyBot

public static Document postDocument(String url, Map<String, String> header, Map<String, String> data) throws IOException {
  return Jsoup.connect(url)
      .userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0")
      .referrer("http://www.google.com")
      .headers(header)
      .data(data)
      .timeout(10000)
      .validateTLSCertificates(false)
      .post();
}

代码示例来源:origin: io.github.christian-draeger/page-content-tester

.method(params.getMethod())
.validateTLSCertificates(false)
.ignoreHttpErrors(true)
.followRedirects(params.isFollowRedirects())

代码示例来源:origin: xuxueli/xxl-crawler

conn.validateTLSCertificates(pageRequest.isValidateTLSCertificates());
conn.maxBodySize(0);    // 取消默认1M限制

代码示例来源:origin: xuxueli/xxl-crawler

conn.validateTLSCertificates(pageRequest.isValidateTLSCertificates());
conn.maxBodySize(0);    // 取消默认1M限制

代码示例来源:origin: yy1193889747/springboot-demo

Jsoup.connect("").validateTLSCertificates(false).execute();

相关文章