我正在尝试从HtmlUnit访问页面https://www-banner.aub.edu.lb/pls/weba/bwckschd.p_disp_dyn_sched。从任何浏览器访问页面时,页面不需要任何身份验证,但是,当您通过代码访问它时,它会将我重定向到登录页面!任何解释和解决方案?
这是我的代码:
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();
答案 0 :(得分:0)
可能是服务器并不完全信任您的虚拟浏览器(webclient),因为webclient可能不提供所有标头信息。
如果你还没有这样做,你可能想看看this other related question。特别是,尝试启用不安全的SSL。设置会话cookie可能是另一种可能的解决方案