Picasso:UnknownServiceException:未为客户端

时间:2017-01-09 15:23:35

标签: android picasso

我在我的应用程序中使用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。是毕加索的虫子吗?如何解决?

2 个答案:

答案 0 :(得分:8)

  

是Picasso的错误吗?

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

  

如何解决?

使用https网址。

如果某个恶魔般的狂人威胁要炸毁一个小城市,除非你使用普通http,请通过其OkHttpClient配置Builder,包括致电connectionSpecs()指出您愿意支持的HTTP连接类型。例如:

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

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

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

答案 1 :(得分: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);