当前位置:  开发笔记 > 运维 > 正文

Picasso:UnknownServiceException:未为客户端启用CLEARTEXT通信

如何解决《Picasso:UnknownServiceException:未为客户端启用CLEARTEXT通信》经验,为你挑选了1个好方法。

我在我的应用程序中使用Picasso 2.5.2.它运行良好,但无法从第三方服务器之一加载图片.当我尝试从此站点加载图片时,我收到此错误:

java.net.UnknownServiceException: CLEARTEXT communication not enabled for client
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:98)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:196)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:132)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:101)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
at okhttp3.RealCall.execute(RealCall.java:63)
at com.jakewharton.picasso.OkHttp3Downloader.load(OkHttp3Downloader.java:136)
at com.squareup.picasso.NetworkRequestHandler.load(NetworkRequestHandler.java:47)
at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:206)
at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)

当我在浏览器中打开此图像时,它会成功加载.网址看起来像http://somesite.com/path/to/file/123456.jpg.是毕加索的虫子吗?怎么解决?



1> CommonsWare..:

是毕加索的虫子吗?

我不这么认为.OkHttp默认情况下似乎阻止非SSL通信.我几年没有使用OkHttp进行纯文本HTTP请求,但这是我在检查与该错误消息相关的代码时看到的内容.

怎么解决?

使用httpsURL.

如果某个恶魔般的狂人威胁要炸毁一个小城市,除非你使用普通http,请配置OkHttpClient通过它Builder,包括调用connectionSpecs()以指示你愿意支持哪种HTTP连接.例如:

.connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT))

将允许"现代TLS"(不完全确定什么是合格的)和普通的HTTP.

然后,将它OkHttpClient用于Picasso,以及使用OkHttp直接进行的任何操作.

推荐阅读
帆侮听我悄悄说星星
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有