com.gargoylesoftware.htmlunit.WebClient.setUseInsecureSSL()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(161)

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

WebClient.setUseInsecureSSL介绍

[英]If set to true, the client will accept connections to any host, regardless of whether they have valid certificates or not. This is especially useful when you are trying to connect to a server with expired or corrupt certificates.
[中]如果设置为true,客户端将接受到任何主机的连接,无论它们是否具有有效证书。当您试图连接到证书过期或损坏的服务器时,这尤其有用。

代码示例

代码示例来源:origin: stackoverflow.com

WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
 client.setTimeout(60000);
 client.setRedirectEnabled(true);
 client.setJavaScriptEnabled(true);
 client.setThrowExceptionOnFailingStatusCode(false);
 client.setThrowExceptionOnScriptError(false);
 client.setCssEnabled(false);
 client.setUseInsecureSSL(true);

代码示例来源:origin: stackoverflow.com

WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
client.setTimeout(60000);
client.setRedirectEnabled(true);
client.setJavaScriptEnabled(true);
client.setThrowExceptionOnFailingStatusCode(false);
client.setThrowExceptionOnScriptError(false);
client.setCssEnabled(false);
client.setUseInsecureSSL(true);

  HtmlPage page = null;
  try {
    page = client.getPage("http://www.whatever.com");
  } catch (Exception e) {
    // TODO Auto-generated catch block
  }
  if (page.getWebResponse().getStatusCode() == 404) {
    System.out.println("Page not found");
  }

  // Post a request
  WebRequest request = new WebRequest(new URL("http://www.whatever.com/post_url"));
  request.setHttpMethod(HttpMethod.POST);
  List<NameValuePair> params = new ArrayList<NameValuePair>();
  params.add(new NameValuePair("login", userLogin));
  params.add(new NameValuePair("pass", userPassword));
  request.setRequestParameters(params);

  page = client.getPage(request);

代码示例来源:origin: stackoverflow.com

public String getPageSourceFromBrowser(String url) throws SiteAnalizeException {    
   WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6); 
   HtmlPage firstPage = null;
   String result = null;
   try {
     webClient.setJavaScriptEnabled(true);
     webClient.setThrowExceptionOnScriptError(false);
     webClient.setCssEnabled(false);
     webClient.setUseInsecureSSL(false);
     webClient.setRedirectEnabled(true);
     firstPage = webClient.getPage(new URL(url));  
     result = firstPage.getWebResponse().getContentAsString("UTF-8");
     DomNodeList<HtmlElement> button = firstPage.getElementsByTagName("a");
     for (HtmlElement htmlElement : button) {
      if(htmlElement.asText().equals("Buy Now")) {
        HtmlPage page = htmlElement.click();
        //HtmlElement button2 = page.getElementById("market_buynow_dialog_addfunds");
        //HtmlPage page2 = button2.click();
            String htmlBody = page.getWebResponse().getContentAsString(); 
        System.out.println(htmlBody);              
      }
     }
}

代码示例来源:origin: org.openqa.selenium.webdriver/webdriver-htmlunit

private WebClient createWebClient(BrowserVersion version) {
  WebClient client = newWebClient(version);
  client.setThrowExceptionOnFailingStatusCode(false);
  client.setPrintContentOnFailingStatusCode(false);
  client.setJavaScriptEnabled(enableJavascript);
  client.setRedirectEnabled(true);
  try {
    client.setUseInsecureSSL(true);
  } catch (GeneralSecurityException e) {
    throw new WebDriverException(e);
  }
  // Ensure that we've set the proxy if necessary
  if (proxyConfig != null)
    client.setProxyConfig(proxyConfig);
  return modifyWebClient(client);
}

相关文章

WebClient类方法