Using Apache HttpClient with Android SDK 23. NoSuchMethod



已经在google上创建了一个bugticket。可能有人有什么想法吗?

我想在Apache库中使用一个正常的HTTPClient (CloseableHttpClient),

mCloseableHttpClient = HttpClientBuilder.create()
                .setDefaultRequestConfig(defaultRequestConfig)
                .setUserAgent(userAgent)
                .build();

和应用程序总是直接崩溃:

java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/ext.jar)
            at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
            at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:912)

API级别22 ( API级别 23 )。

问题是:Android SDK 中的类没有声明INSTANCE字段。

以下类已从API级别22删除

org.apache.http.conn.ssl.AllowAllHostnameVerifier

您可以在官方api更改中看到删除的类

你可以使用HttpURLConnection类来代替。

根据官方指南

这个API更高效,因为它通过透明压缩和响应缓存减少了网络使用,并最大限度地降低了功耗

** EDIT **

根据CommonsWare下面的评论,还有其他第三方选项,包括OkHttp或Apache的独立的Android HttpClient库

是一个库版本的问题,尝试使用这个版本

implementation 'org.apache.httpcomponents:httpclient:4.5.3'
    api 'org.apache.httpcomponents:httpcore:4.4.6'
    api 'org.apache.httpcomponents:httpmime:4.3.6'

最新更新