2

我有一个应用程序需要 httpclient-4.2.5.jar 库才能正确运行。我还想使用 HtmlUnit 库(2.12 版)。由于库冲突(httpclient-4.2.5.jar 和 htmlunit-2.12.jar 之间),它失败了(我认为)

这是我的日志的输出,但我不太了解它对我说的内容,因为我没有在日志中调用任何这些方法......

Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException:   org.apache.http.conn.ssl.SSLSocketFactory.createDefaultSSLContext()
    at  com.gargoylesoftware.htmlunit.HtmlUnitSSLSocketFactory.createSSLContext(HtmlUnitSSLSocketFactory.java:119)
    at com.gargoylesoftware.htmlunit.HtmlUnitSSLSocketFactory.<init>(HtmlUnitSSLSocketFactory.java:102)
    at com.gargoylesoftware.htmlunit.HtmlUnitSSLSocketFactory.buildSSLSocketFactory(HtmlUnitSSLSocketFactory.java:77)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.configureHttpsScheme(HttpWebConnection.java:608)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:555)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClient(HttpWebConnection.java:518)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:155)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1486)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1403)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:305)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:374)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:359) 
4

5 回答 5

3

这一切都很简单。HtmlUnit 通过反射利用了 HttpClient 代码中的私有方法:

http://sourceforge.net/p/htmlunit/code/8377/tree/trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HtmlUnitSSLSocketFactory.java#l113

有问题的方法在版本 4.2.4 中被删除。请参阅HTTPCLIENT-1320

于 2013-07-06T14:27:20.887 回答
2

好吧,对我有用的唯一解决方案是降级到 httpclient 4.2 - http://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.2

于 2013-07-06T10:19:42.460 回答
2

将 htmlunit 版本提升到 2.15 可以解决问题。为我工作

于 2014-10-09T01:46:55.117 回答
0

快速检查“org.apache.http.conn.ssl.SSLSocketFactory”类文档,那里没有这样的“createDefaultSSLContext()”方法。

于 2013-07-05T22:45:13.603 回答
0

我遇到了这个问题,因为我想在 Selenium 中使用 WebClient。

我将 Selenium 从 2.33.0 升级到 2.45.0,之后 WebClient 运行良好。

于 2015-04-02T09:31:54.747 回答