如何使用htmlUnit登录HTTPS站点?
How to log-in to HTTPS site using htmlUnit?
我尝试使用以下 webclient 配置登录 HTTPS 站点,但似乎无法登录。
final WebClient webClient = new WebClient(BrowserVersion.getDefault(), "10.52.252.31", 8080);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setAppletEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.waitForBackgroundJavaScript(100000);
webClient.getOptions().setUseInsecureSSL(true);
如果有任何解决方法,请提供示例代码。
我在关注 link 后得到了答案。
实际上我们应该在登录HTTPS站点时使用Xpath代替HtmlUnit中的getElementById方法来解决这个问题。
我尝试使用以下 webclient 配置登录 HTTPS 站点,但似乎无法登录。
final WebClient webClient = new WebClient(BrowserVersion.getDefault(), "10.52.252.31", 8080);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setAppletEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.waitForBackgroundJavaScript(100000);
webClient.getOptions().setUseInsecureSSL(true);
如果有任何解决方法,请提供示例代码。
我在关注 link 后得到了答案。
实际上我们应该在登录HTTPS站点时使用Xpath代替HtmlUnit中的getElementById方法来解决这个问题。