Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用时httpclient冲突的问题 #13

Open
spyatsea opened this issue Dec 15, 2020 · 0 comments
Open

调用时httpclient冲突的问题 #13

spyatsea opened this issue Dec 15, 2020 · 0 comments

Comments

@spyatsea
Copy link

由于HttpClient现在已经被Android移除,所以在调用时很有可能会报“No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier”的错误。
我的解决方法是:
1、不引用java-sms-sdk,在项目的build.gradle中删除下面引用:
implementation 'com.cloopen:java-sms-sdk:1.0.3'
添加下面引用:
implementation 'dom4j:dom4j:1.6.1' //noinspection DuplicatePlatformClasses implementation 'cz.msebera.android:httpclient:4.5.8'
2、将src/main/java/com/cloopen/rest/sdk/中的代码拷贝到自己项目中。
3、修改com.cloopen.rest.sdk.utils.HttpClientUtil.java。将之前对“org.apache.http”的引用,改为对“cz.msebera.android.httpclient”的引用。之前是这样:
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils;

现在改成这样:
import cz.msebera.android.httpclient.HttpEntity; import cz.msebera.android.httpclient.HttpStatus; import cz.msebera.android.httpclient.NameValuePair; import cz.msebera.android.httpclient.client.config.RequestConfig; import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity; import cz.msebera.android.httpclient.client.methods.CloseableHttpResponse; import cz.msebera.android.httpclient.client.methods.HttpPost; import cz.msebera.android.httpclient.message.BasicNameValuePair; import cz.msebera.android.httpclient.conn.ssl.SSLConnectionSocketFactory; import cz.msebera.android.httpclient.conn.ssl.TrustStrategy; import cz.msebera.android.httpclient.entity.ContentType; import cz.msebera.android.httpclient.entity.StringEntity; import cz.msebera.android.httpclient.impl.client.CloseableHttpClient; import cz.msebera.android.httpclient.impl.client.HttpClients; import cz.msebera.android.httpclient.ssl.SSLContexts; import cz.msebera.android.httpclient.util.EntityUtils;

4、我还把org.apache.commons.logging的调用都注释掉了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant