使用htmlunit连接https网页时,会出现证书异常,如题。
解决办法如下:
final WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setActiveXNative(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setUseInsecureSSL(true);//添加这句,放弃ssl验证
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
亲测可用,取消ssl证书的检验