2013-03-05 71 views
0

我試圖從HtmlUnit訪問頁面https://www-banner.aub.edu.lb/pls/weba/bwckschd.p_disp_dyn_sched。當您從任何瀏覽器訪問該頁面時,該頁面不需要任何身份驗證,但是,當您通過代碼訪問該頁面時,該頁面會將我重定向到登錄頁面!任何解釋和解決方案?頁面驗證不需要通過瀏覽器,但需要從HtmlUnit

這是我的代碼:

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

它可能是服務器並不完全相信你的虛擬瀏覽器(Web客戶端),因爲它可能是Web客戶端不提供所有頭信息的情況。

如果你還沒有這樣做,你可能會想看看this other related question。特別是嘗試啓用不安全的SSL。設置會話cookie可能是另一種可能的解決方案