0

我已经成功地在测试 java 项目中正确地运行了这个问题中的代码但是当我按照完全相同的过程在我的网络服务器中导入 HtmlUnit 时,我不断收到org.apache.http.protocol.BasicHttpContext: method <init>()V not found错误消息。

我试图运行的代码:

    package com.testing;

import java.io.IOException;
import java.net.MalformedURLException;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;

public class testingUnit {

    public static void main(final String[] args) {
        final WebClient webClient = new WebClient();
        webClient.setTimeout(1000);
        try {
            System.out.println("Querying");
            webClient.getPage("https://bulksms.vsms.net/register/");
            System.out.println("Success");
        } catch (final FailingHttpStatusCodeException e) {
            System.out.println("One");
            e.printStackTrace();
        } catch (final MalformedURLException e) {
            System.out.println("Two");
            e.printStackTrace();
        } catch (final IOException e) {
            System.out.println("Three");
            e.printStackTrace();
        } catch (final Exception e) {
            System.out.println("Four");
            e.printStackTrace();
        }
        System.out.println("Finished");
    }

}

安慰:

Querying
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.protocol.BasicHttpContext: method <init>()V not found
    at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:273)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:797)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:152)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1439)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1358)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:373)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:358)
    at com.testing.testingUnit.main(testingUnit.java:16)

在此处输入图像描述

4

1 回答 1

0

在这里发布屏幕截图后想通了。我完全忘记了更新网络应用程序库。我这样做并删除了我拥有的所有过时版本的 jars(在 webcontent/lib 文件夹中),上面的代码就像一个魅力。干杯!

于 2012-07-20T15:20:29.753 回答