0
我試圖在登錄到應用程序後直接訪問URL(admin.do
),並且該URL是受限制的頁面。但是,當我在瀏覽器上運行場景時,我能夠看到頁面被重定向到訪問被拒絕的頁面。但是,當我使用htmlunit運行相同的操作時,我會看到以下異常。HtmlUnit + Webclient.getPage引發
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 403 Forbidden for https://localhost:27216/app/admin.do
at com.gargoylesoftware.htmlunit.WebClient.throwFailingHttpStatusCodeExceptionIfNecessary(WebClient.java:536)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:331)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:387)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:372)
任何想法如何實現這一目標?這是我的代碼。
HtmlPage resp = null;
WebClient webClient = getWebClient();
HtmlPage page = (HtmlPage) webClient.getPage(url);
檢查標題。這可能是瀏覽器捕獲了cookie,而htmlunit忽略了它。 –