2017-01-09 75 views
1

我在我的应用程序中使用了Picasso 2.5.2。它运行良好,但无法从第三方服务器加载图片。当我尝试从本站下载图片时,出现此错误:Picasso:UnknownServiceException:CLEARTEXT通信未启用客户端

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。是毕加索的错误吗?如何解决它?

回答

3

Is it Picasso bug?

我不这么认为。 OkHttp默认情况下似乎阻止非SSL通信。我没有用OkHttp在很长一段时间内完成纯文本的HTTP请求,但这是我从检查与该错误消息相关的代码中看到的。

How to fix it?

使用https URL。

如果某些恶魔疯子扬言要炸毁一个小城市,除非你使用纯http,通过其Builder配置OkHttpClient,包括connectionSpecs()一个电话,表示你愿意支持什么类型的HTTP连接。例如:

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

将使 “现代TLS”(不完全肯定什么资格)和普通HTTP。

然后,使用OkHttpClient作为毕加索以及任何直接使用OkHttp的作品。

1

我已经搜索了您的问题。我认为你在okhttp3上遇到了问题,如https://github.com/fabric8io/kubernetes-client/issues/498的问题 - 验证连接出现问题。您可以尝试通过向毕加索的下载解决通过定制:

// create Picasso.Builder object 
Picasso.Builder picassoBuilder = new Picasso.Builder(context); 

// let's change the standard behavior before we create the Picasso instance 
// for example, let's switch out the standard downloader for the OkHttpClient 
picassoBuilder.downloader(new OkHttpDownloader(new OkHttpClient())); 
// or you can try 

(picassoBuilder.downloader( 
    new OkHttpDownloader(
     UnsafeOkHttpClient.getUnsafeOkHttpClient() 
    ) 
);) 

// Picasso.Builder creates the Picasso object to do the actual requests 
Picasso picasso = picassoBuilder.build(); 

现在你可以使用你的毕加索加载图像。

picasso 
    .load(linktoimage) 
    .into(imageView3); 
+1

请记住,在互联网上浮动的'UnsafeOkHttpClient'实施是一个安全灾难,并且会让你从Play商店被禁止。不要使用盲目接受所有SSL证书的代码。 – CommonsWare

+1

我只发现你的问题。我认为连接okhttp的问题。如果您发现问题,请分享您的解决方案(您可以尝试使用@CommonsWare解决方案)。谢谢。 –