为 android 安装更新的 Apache Http 组件
Setup Updated Apache Http Components for android
我在 apache HttpClient 4.5 中使用的代码在单独的 java 应用程序中工作正常,当我带到 android 项目时出现此错误
java.lang.nosuchfielderror org.apache.http.conn.ssl.allowallhostnameverifier
代码:
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(),new HostnameVerifier(){
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
我导入相同的库,我用谷歌搜索并说重复引用或遗漏了一个 jar,但没有
我从这里下载 jar https://hc.apache.org/downloads.cgi
如果问题出在与 android 不兼容的罐子中,我喜欢在不使用 gradle maven 或类似的东西的情况下找到正确的罐子,因为市长时间我处于离线状态并且在线时只能浏览网络
谢谢
您不能导入 httpclient,因为它会与现有库发生冲突。
不管你想怎么用,这是apache官方推荐的方式
https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html
Background
Google Android 1.0 was released with a pre-BETA snapshot of Apache
HttpClient. To coincide with the first Android release Apache
HttpClient 4.0 APIs had to be frozen prematurely, while many of
interfaces and internal structures were still not fully worked out. As
Apache HttpClient 4.0 was maturing the project was expecting Google to
incorporate the latest code improvements into their code tree.
Unfortunately it did not happen. Version of Apache HttpClient shipped
with Android has effectively become a fork. Eventually Google decided
to discontinue further development of their fork while refusing to
upgrade to the stock version of Apache HttpClient citing compatibility
concerns as a reason for such decision. As a result those Android
developers who would like to continue using Apache HttpClient APIs on
Android cannot take advantage of newer features, performance
improvements and bug fixes.
Apache HttpClient 4.3 port for Android is intended to remedy the
situation by providing official releases compatible with Google
Android.
或者你也可以考虑okhttp,不过好像okhttp现在已经包含在AndroidM上了,我没有测试过会不会有类似的冲突。
okhttp,有两种wrapper,一种类似于urlConnection,一种类似于httpclient,你应该可以在很短的时间内迁移。
我在 apache HttpClient 4.5 中使用的代码在单独的 java 应用程序中工作正常,当我带到 android 项目时出现此错误
java.lang.nosuchfielderror org.apache.http.conn.ssl.allowallhostnameverifier
代码:
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(),new HostnameVerifier(){
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
我导入相同的库,我用谷歌搜索并说重复引用或遗漏了一个 jar,但没有 我从这里下载 jar https://hc.apache.org/downloads.cgi 如果问题出在与 android 不兼容的罐子中,我喜欢在不使用 gradle maven 或类似的东西的情况下找到正确的罐子,因为市长时间我处于离线状态并且在线时只能浏览网络 谢谢
您不能导入 httpclient,因为它会与现有库发生冲突。
不管你想怎么用,这是apache官方推荐的方式
https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html
Background
Google Android 1.0 was released with a pre-BETA snapshot of Apache HttpClient. To coincide with the first Android release Apache HttpClient 4.0 APIs had to be frozen prematurely, while many of interfaces and internal structures were still not fully worked out. As Apache HttpClient 4.0 was maturing the project was expecting Google to incorporate the latest code improvements into their code tree. Unfortunately it did not happen. Version of Apache HttpClient shipped with Android has effectively become a fork. Eventually Google decided to discontinue further development of their fork while refusing to upgrade to the stock version of Apache HttpClient citing compatibility concerns as a reason for such decision. As a result those Android developers who would like to continue using Apache HttpClient APIs on Android cannot take advantage of newer features, performance improvements and bug fixes.
Apache HttpClient 4.3 port for Android is intended to remedy the situation by providing official releases compatible with Google Android.
或者你也可以考虑okhttp,不过好像okhttp现在已经包含在AndroidM上了,我没有测试过会不会有类似的冲突。 okhttp,有两种wrapper,一种类似于urlConnection,一种类似于httpclient,你应该可以在很短的时间内迁移。