美文网首页
Android9.0使用HttpClient访问https崩溃问

Android9.0使用HttpClient访问https崩溃问

作者: fireflower2009 | 来源:发表于2020-04-15 10:58 被阅读0次

网络请求java.lang.IncompatibleClassChangeError: Class 'org.apache.http.conn.ssl.SSLSocketFactory' does not implement interface 'org.apache.http.conn.scheme.SchemeSocketFactory' in call to 'java.net.Socket错误
程序测试的时候跑的好好的。但是在访问链接换成正式版的https的时候就崩溃了。try-catch都没用。
用的包版本


image.png

百度了一下,在application里面添加
android:usesCleartextTraffic="true"
在gradle里面添加
useLibrary 'org.apache.http.legacy'
都不行。
还是谷歌大法好,在外面找到解决方法:


image.png
以下方便copy
/Important for android version 9 pie/
httpClient.getConnectionManager().getSchemeRegistry().register(
new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)

);

相关文章

网友评论

      本文标题:Android9.0使用HttpClient访问https崩溃问

      本文链接:https://www.haomeiwen.com/subject/xriqvhtx.html