HtmlUnit getPage()抛出异常



HtmlUnit的getPage()函数并不总是抛出javax.net.ssl.SSLException: Invalid TLS padding datajavax.net.ssl.SSLException: Received fatal alert: bad_record_mac,而是在两个三个请求之后开始抛出异常。

URL使用HTTPS协议

你知道它有什么问题吗?如何解决?

片段:

调用多个请求的网页抛出上述异常:

public static WebClient getLoggedInHtmlUnit() {

        webClient = new WebClient(BrowserVersion.FIREFOX_24);
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setCssEnabled(false); // I think this speeds the thing up
        webClient.getOptions().setRedirectEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());
        webClient.getCookieManager().setCookiesEnabled(true);
        webClient.getOptions().setUseInsecureSSL(true);

        try {
            final HtmlPage page =  webClient.getPage(LOGIN_URL); //https://consyn.elsevier.com/user/login
            final HtmlForm form = page.getForms().get(0);  
            final HtmlTextInput textField =  form.getInputByName(USERNAME_BYINPUT_NAME);
            final HtmlPasswordInput pwd =  form.getInputByName(PASSWORD_BYINPUT_NAME);        
            textField.setValueAttribute(USERNAME);
            pwd.setValueAttribute(PASSWORD);   
            final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue(LOGIN_BYVALUE).get(0);
            button.click();
            return webClient;
        } catch (FailingHttpStatusCodeException | IOException e) {
            e.printStackTrace();
            return null;
        }

}

我使用了下面的代码,它工作得很好,并打印了"Page Loaded…". 在Try catch块 内使用这个,而不是在外使用。我试过在Ubuntu Linux环境下使用jdk 6。如果此操作失败,请检查MAC以外的其他操作系统(我认为您正在使用MAC)

            WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
            webClient.getOptions().setJavaScriptEnabled(false);
            webClient.getOptions().setUseInsecureSSL(true);
            HtmlPage page = (HtmlPage)     webClient.getPage("https://consyn.elsevier.com/user/login");
            System.out.println("Page Loaded ...");

相关内容

  • 没有找到相关文章

最新更新