gpt4 book ai didi

java - HtmlUnit + Webclient.getPage 抛出

转载 作者:行者123 更新时间:2023-12-02 03:35:42 25 4
gpt4 key购买 nike

我尝试在登录应用程序后直接访问 URL (admin.do),并且该 URL 是受限制的页面。但是,当我在浏览器上运行该场景时,我可以看到页面被重定向到访问被拒绝的页面。但是,当我使用 htmlunit 运行相同的操作时,我看到以下异常。

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

最佳答案

成功了。抛出异常,因此不允许页面遵循重定向。我将 WebClient 上的属性 throwExceptionOnFailingStatusCode 设置为 false,以便忽略异常。

HtmlPage resp = null;
WebClient webClient = getWebClient();
webClient.setThrowExceptionOnFailingStatusCode(false);
HtmlPage page = (HtmlPage) webClient.getPage(url);

关于java - HtmlUnit + Webclient.getPage 抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37478549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com