Java 不需要通过浏览器进行页面身份验证,但需要通过HtmlUnit进行页面身份验证

Java 不需要通过浏览器进行页面身份验证,但需要通过HtmlUnit进行页面身份验证,java,htmlunit,Java,Htmlunit,我正在尝试访问一个页面,它来自HtmlUnit。当您从任何浏览器访问该页面时,它不需要任何身份验证,但是,当您通过代码访问该页面时,它会将my重定向到登录页面!有什么解释和解决办法吗 这是我的代码: final WebClient webClient = new WebClient(); // Get the first page final HtmlPage page1 = webClient.getPage("http://www-banner.aub.edu.lb

我正在尝试访问一个页面,它来自HtmlUnit。当您从任何浏览器访问该页面时,它不需要任何身份验证,但是,当您通过代码访问该页面时,它会将my重定向到登录页面!有什么解释和解决办法吗

这是我的代码:

    final WebClient webClient = new WebClient();

    // Get the first page
    final HtmlPage page1 = webClient.getPage("http://www-banner.aub.edu.lb/pls/weba/bwckschd.p_disp_dyn_sched");

    // Get the form that we are dealing with and within that form, 
    // find the submit button and the field that we want to change.

    final HtmlForm form=page1.getFirstByXPath("//form[@action='/pls/weba/bwckgens.p_proc_term_date']");

    final HtmlSubmitInput button = form.getInputByValue("Submit");
    final HtmlHiddenInput field = form.getInputByName("p_calling_proc");

    // Change the value of the text field
    field.setValueAttribute("201350");

    // Now submit the form by clicking the button and get back the second page.
    final HtmlPage page2 = button.click();

可能是服务器不完全信任您的虚拟浏览器(webclient),因为webclient可能不提供所有的头信息

如果你还没有这样做,你可能想看看。特别是,尝试使用不安全的SSL。设置会话cookie可能是另一种可能的解决方案