HtmlUnit getPage()抛出异常

时间:2014-05-27 06:36:02

标签: java htmlunit htmlunit-driver

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

网址使用HTTPS协议。

知道它有什么问题吗?怎么解决?

SNIPPET:

调用网页以查看超出异常的多个请求:

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;
        }



}

1 个答案:

答案 0 :(得分:0)

我使用了以下内容并且工作正常并打印了#Page; 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 ...");