为什么 htmlunit getPage 使用 nosuchmenthod 来解决这个问题

Why is htmlunit getPage is making this issues with nosuchmenthod

我在连接到网站时遇到此错误。 Website

java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.toString(Ljava/io/InputStream;Ljava/nio/charset/Charset;)Ljava/lang/String;
at com.gargoylesoftware.htmlunit.WebResponse.getContentAsString(WebResponse.java:242)

我正在使用 htmlunit 2.29 并在测试时

    WebClient client;
    HtmlPage homePage;
    Document doc = null;
    try {
        client = new WebClient(BrowserVersion.FIREFOX_52);
        client.getOptions().setUseInsecureSSL(true);
        client.setAjaxController(new NicelyResynchronizingAjaxController());
        client.getOptions().setThrowExceptionOnFailingStatusCode(false);
        client.getOptions().setThrowExceptionOnScriptError(false);
        client.waitForBackgroundJavaScript(20000);
        client.waitForBackgroundJavaScriptStartingBefore(20000);
        client.getOptions().setCssEnabled(false);
        client.getOptions().setJavaScriptEnabled(true);
        client.getCache().setMaxSize(0);

        homePage = client.getPage(url);

我已经在单独的新 class 中对其进行了测试。它正常工作。 但是在其他项目中使用这个(client.getPage(url);)功能块时,
它给出
noSUchMethodError from IOUtils.toString class.

这里可能遗漏了什么?

通常这是因为依赖关系被破坏了。确保你的类路径中有正确版本的 apache.commons.io 并检查重复项。

顺便说一句:

client.waitForBackgroundJavaScript(20000);
client.waitForBackgroundJavaScriptStartingBefore(20000);

没有选项,在您的客户端设置期间执行这些调用是无用的。在使用 c&p 之前,请阅读 Whosebug 上的所有帖子。