2017-01-09 78 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解決方案)。謝謝。 –