Glide не загружает URL-адрес изображения - PullRequest
1 голос
/ 14 июля 2020

Я пытаюсь загрузить URL изображения с помощью Glide. Ошибка.

class com.bumptech.glide.load.engine.GlideException: не удалось загрузить ресурс

Я искал эту ошибку в Google, он говорит о проблеме https, но предыдущий i работал в другом проекте, который также https.it работал нормально. почему проблема https или это какая-то другая проблема?

Эти ссылки работают нормально

Но они не работают

ссылка на изображение

Загрузка изображения:

   Glide.with(context)
            .load(bannerImageModel.getOutput().get(position).getBanner_img())
            .apply(new RequestOptions().
            diskCacheStrategy(DiskCacheStrategy.ALL))
            .into(view);

ссылка 1: https://freshtocook.in/uploads/banner/47a16ffc2fc5935dccd37574083c6201.jpg

ссылка 2: https://freshtocook.in/uploads/banner/7eecf823e008a0bb93f347d994b6e534.jpg

ссылка 3: https://freshtocook.in/uploads/banner/62d69dfa30acabbfe60bc77c5f19cc53.jpg

Полная ошибка:

javax. net .ssl.SSLHandshakeException (java .security. cert.CertPathValidatorException: якорь доверия для пути сертификации не найден.) вызовите GlideException # logRootCauses (String) для получения более подробной информации Причина (1 из 1): class com.bumptech.glide.load.engine.GlideException: Не удалось получить данные, класс java .io.InputStream, REMOTE Была 1 причина: javax. net .ssl.SSLHandshakeException (java .security.cert.CertPathValidator Исключение: якорь доверия для пути сертификации не найден.) Для получения дополнительных сведений вызовите GlideException # logRootCauses (String) Причина (1 из 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed Была 1 причина: javax. net .ssl.SSLHandshakeException (java .security.cert.CertPathValidatorException: якорь доверия для пути сертификации не найден.) Вызовите GlideException # logRootCauses (String) для получения дополнительных сведений Причина (1 из 1): класс javax. net .ssl.SSLHandshakeException: java .security.cert.CertPathValidatorException: якорь доверия для пути сертификации не найден. 2020-07-14 18: 25: 03.367 24169-24169 / com.example.freshtocook I / Glide: Root причина (1 из 1) javax. net .ssl.SSLHandshakeException: java .security.cert. CertPathValidatorException: якорь доверия для пути сертификации не найден. на com. android .org.conscrypt.ConscryptFileDescriptorSocket.startHandshake (ConscryptFileDescriptorSocket. java: 239) на com. android .okhttp.internal.io.RealConnection.connectTls (RealConnection *: 1471. * 10 . android .okhttp.internal.io.RealConnection.connectSocket (RealConnection. java: 1415) в com. android .okhttp.internal.io.RealConnection.connect (RealConnection. java: 1359) в com. . android .okhttp.internal.http.StreamAllocation.findConnection (StreamAllocation. java: 221) в com. android .okhttp.internal.http.StreamAllocation.findHealthyConnection (StreamAllocation. java: 144) в com. . android .okhttp.internal.http.StreamAllocation.newStream (StreamAllocation. java: 106) в com. android .okhttp.internal.http.HttpEngine.connect (HttpEngine. java: 400) в com. . android .okhttp.internal.http.HttpEngine.sendRequest (HttpEngine. java: 333) в com. android .okhttp.internal.hu c .HttpURLConnectionImpl.execute (HttpURLConnectionImpl. * 1074 ) на com. android .okhttp.internal.hu c .HttpURLConnectionImpl.connect (Http URLConnectionImpl. java: 135) на com. android .okhttp.internal.hu c .DelegatingHttpsURLConnection.connect (DelegatingHttpsURLConnection. java: 90) на com. android .okhttp.internal.hu c .HttpsURLConnectionImpl.connect (HttpsURLConnectionImpl. java: 30) по адресу com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects (HttpUrlFetcher. java. 104) по адресу com.bumptechata.glidecher.load loadData (HttpUrlFetcher. java: 59) в com.bumptech.glide.load.model.MultiModelLoader $ MultiFetcher.loadData (MultiModelLoader. java: 100) в com.bumptech.glide.load.model.MultiModelLoader $ MultiFetcher. startNextOrFail (MultiModelLoader. java: 164) в com.bumptech.glide.load.model.MultiModelLoader $ MultiFetcher.onLoadFailed (MultiModelLoader. java: 154) в com.bumptech.glide.load.data.Http HttpUrlFetcher. java: 65) в com.bumptech.glide.load.model.MultiModelLoader $ MultiFetcher.loadData (MultiModelLoader. java: 100) в com.bumptech.glide.load.engine.SourceGenerator.startNext (SourceGenerator . java: 62) в com.bumptech.glide.load.engine.DecodeJob.runGenerators (DecodeJob. java: 309) в com.bumptech.glide.load.engine.DecodeJob. runWrapped (DecodeJob. java: 279) в com.bumptech.glide.load.engine.DecodeJob.run (DecodeJob. java: 235) в java .util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor. java: 1167) в java .util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor. java: 641) в java .lang.Thread.run (Thread. java: 919) в com.bumptech .glide.load.engine.executor.GlideExecutor $ DefaultThreadFactory $ 1.run (GlideExecutor. java: 446) Вызвано: java .security.cert.CertificateException: java .security.cert.CertPathValidatorException: Якорь доверия для путь сертификации не найден. на com. android .org.conscrypt.TrustManagerImpl.checkTrustedRecursive (TrustManagerImpl. java: 668) на com. android .org.conscrypt.TrustManagerImpl.checkTrusted (TrustManagerImpl. java: * 513) на. com. com. 1108 * .org.conscrypt.TrustManagerImpl.checkTrusted (TrustManagerImpl. java: 432) в com. android .org.conscrypt.TrustManagerImpl.getTrustedChainForServer (TrustManagerImpl. java: 360security. android: 360security. * 1112 1113 * .config.NetworkSecurityTrustManager.checkServerTrusted (NetworkSecurityTrustManager. java: 94) в android .security. net .config.RootTrustManager.checkServerTrusted (RootTrustManager. *. * 1117. .conscrypt.Platform.checkServerTrusted (Platform. java: 224) на com. android .org.conscrypt.ConscryptFileDescriptorSocket.verifyCertificateChain (ConscryptFileDescriptorSocket. java: 430) на com. *1121*: 430) на com. * 1120 .SSL_do_handshake (собственный метод) на com. android .org.conscrypt.NativeSsl.doHandshake (NativeSsl. java: 387) на com. android .org.conscrypt.ConscryptFileDescriptorSocket.startHandsha ke (ConscryptFileDescriptorSocket. java: 234) на com. android .okhttp.internal.io.RealConnection.connectTls (RealConnection. java: 1471) на com. android .okhttp.internal.io.RealConnection. connectSocket (RealConnection. java: 1415) на com. android .okhttp.internal.io.RealConnection.connect (RealConnection. java: 1359) на com. android .okhttp.internal.http.StreamAllocation. findConnection (StreamAllocation. java: 221) на com. android .okhttp.internal.http.StreamAllocation.findHealthyConnection (StreamAllocation. java: 144) на com. android .okhttp.internal.http.StreamAllocation. newStream (StreamAllocation. java: 106) на com. android .okhttp.internal.http.HttpEngine.connect (HttpEngine. java: 400) на com. android .okhttp.internal.http.HttpEngine. sendRequest (HttpEngine. java: 333) на com. android .okhttp.internal.hu c .HttpURLConnectionImpl.execute (HttpURLConnectionImpl. java: 483) на com. android .okhttp.internal.hu c .HttpURLConnectionImpl.connect (HttpURLConnectionImpl. java: 135) на com. android .okhttp.internal.hu c .D elegatingHttpsURLConnection.connect (DelegatingHttpsURLConnection. java: 90) в com. android .okhttp.internal.hu c .HttpsURLConnectionImpl.connect (HttpsURLConnectionImpl. java: 30) в com.bumptechata.glide .HttpUrlFetcher.loadDataWithRedirects (HttpUrlFetcher. java: 104) в com.bumptech.glide.load.data.HttpUrlFetcher.loadData (HttpUrlFetcher. java: 59) в com.bumptech.glide.load.model.model.model. .loadData (MultiModelLoader. java: 100) в com.bumptech.glide.load.model.MultiModelLoader $ MultiFetcher.startNextOrFail (MultiModelLoader. java: 164) в com.bumptech.glide.load.modelLoader MultiModeloader. .onLoadFailed (MultiModelLoader. java: 154) в com.bumptech.glide.load.data.HttpUrlFetcher.loadData (HttpUrlFetcher. java: 65) в com.bumptech.glide.load.model.MultiModelLoader.load $ MultiFetcher (MultiModelLoader. java: 100) в com.bumptech.glide.load.engine.SourceGenerator.startNext (SourceGenerator. java: 62) в com.bumptech.glide.load.engine.DecodeJob.runGenerators ( DecodeJob. java: 309) в com.bumptech.glide.load.engine.DecodeJob.runWrapped (DecodeJob. java: 279) в com.bumptech.glide.load.engine.DecodeJob.run (DecodeJob. java: 235) в java .util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor. java: 1167) в java .util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor. java: 1170 * .lang.Thread.run (Thread. java: 919) at com.bumptech.glide.load.engine.executor.GlideExecutor $ DefaultThreadFactory $ 1.run (GlideExecutor. java: 446) Вызвано: java .security.cert.CertPathValidatorException: Якорь доверия для пути сертификации не найден. на com. android .org.conscrypt.TrustManagerImpl.checkTrustedRecursive (TrustManagerImpl. java: 668) на com. android .org.conscrypt.TrustManagerImpl.checkTrusted (TrustManagerImpl. java: * 513) на. com. com. 1178 * .org.conscrypt.TrustManagerImpl.checkTrusted (TrustManagerImpl. java: 432) на com. android .org.conscrypt.TrustManagerImpl.getTrustedChainForServer (TrustManagerImpl. java: 360security) на *. * 1182 1183 * .config.NetworkSecurityTrustManager.checkServerTrusted (NetworkSecurityTrustManager. java: 94) в android .security. net .config.RootTrustManager.checkServerTrusted (RootTrustManager. *. * 1187) в com: 1188 *. * 1187 .conscrypt.Platform.checkServerTrusted (Platform. java: 224) по адресу com. android .org.conscrypt.ConscryptFileDescriptorSocket.verifyCertificateChain (ConscryptFileDescriptorSocket. java: 43092porg, com. *1191*: 43092porg). .SSL_do_handshake (собственный метод) на com. android .org.conscrypt.NativeSsl.doHandshake (NativeSsl. java: 387) на com. android .org.conscrypt.ConscryptFileDescriptorSocket.startHandsha ke (ConscryptFileDescriptorSocket. java: 234) на com. android .okhttp.internal.io.RealConnection.connectTls (RealConnection. java: 1471) на com. android .okhttp.internal.io.RealConnection. connectSocket (RealConnection. java: 1415) на com. android .okhttp.internal.io.RealConnection.connect (RealConnection. java: 1359) на com. android .okhttp.internal.http.StreamAllocation. findConnection (StreamAllocation. java: 221) на com. android .okhttp.internal.http.StreamAllocation.findHealthyConnection (StreamAllocation. java: 144) на com. android .okhttp.internal.http.StreamAllocation. newStream (StreamAllocation. java: 106) на com. android .okhttp.internal.http.HttpEngine.connect (HttpEngine. java: 400) на com. android .okhttp.internal.http.HttpEngine. sendRequest (HttpEngine. java: 333) на com. android .okhttp.internal.hu c .HttpURLConnectionImpl.execute (HttpURLConnectionImpl. java: 483) на com. android .okhttp.internal.hu c .HttpURLConnectionImpl.connect (HttpURLConnectionImpl. java: 135) на com. android .okhttp.internal.hu c .D elegatingHttpsURLConnection.connect (DelegatingHttpsURLConnection. java: 90) в com. android .okhttp.internal.hu c .HttpsURLConnectionImpl.connect (HttpsURLConnectionImpl. java: 30) в com.bumptechata.glide .HttpUrlFetcher.loadDataWithRedirects (HttpUrlFetcher. java: 104) в com.bumptech.glide.load.data.HttpUrlFetcher.loadData (HttpUrlFetcher. java: 59) в com.bumptech.glide.load.model.model.model. .loadData (MultiModelLoader. java: 100) в com.bumptech.glide.load.model.MultiModelLoader $ MultiFetcher.startNextOrFail (MultiModelLoader. java: 164) в com.bumptech.glide.load.modelLoader MultiModeloader. .onLoadFailed (MultiModelLoader. java: 154) в com.bumptech.glide.load.data.HttpUrlFetcher.loadData (HttpUrlFetcher. java: 65) в com.bumptech.glide.load.model.MultiModelLoader.load $ MultiFetcherData (MultiModelLoader. java: 100) в com.bumptech.glide.load.engine.SourceGenerator.startNext (SourceGenerator. java: 62) в com.bumptech.glide.load.engine.DecodeJob.runGenerators ( DecodeJob. java: 309) в com.bumptech.glide.load.engine.DecodeJob.runWrapped (DecodeJob. java: 279) в com.bumptech.glide.load.engine.DecodeJob.run (DecodeJob. java: 235) в java .util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor. java: 1167) в java .util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor. java: 1240 * .lang.Thread.run (Thread. java: 919) в com.bumptech.glide.load.engine.executor.GlideExecutor $ DefaultThreadFactory $ 1.run (GlideExecutor. java: 446) 2020-07-14 18: 25: 03.457 24169-24705 / com.example.freshtocook I / System.out: (HTTPLog) -Stati c: isSBSettingEnabled false 2020-07-14 18: 25: 03.458 24169-24705 / com.example.freshtocook I / System. out: (HTTPLog) -Stati c: isSBSettingEnabled false

Теперь появляется эта ошибка с ION lib:

/ ViewRootImpl: sendUserActionEvent () mView вернул. 2020-07-14 18: 46: 15.892 7931-8566 / com.example.freshtocook E / CONSCRYPT: ------------------ Недоверенная цепочка: ------ ---------------- 2020-07-14 18: 46: 15.892 7931-8566 / com.example.freshtocook E / CONSCRYPT: == Chain0 == Версия: 3 2020-07 -14 18: 46: 15,893 7931-8566 / com.example.freshtocook Е / CONSCRYPT: AuthorityKeyIdentifier: 418301680148d8c5ec454ad8ae177e99bf99b05e1b8018d61e1 2020-07-14 18: 46: 15,893 7931-8566 / com.example.freshtocook Е / CONSCRYPT: SubjectKeyIdentifier: 416041493ef6a0cb4e08cbdefeb4fca54cd8872b99d23a0 2020 -07-14 18: 46: 15.893 7931-8566 / com.example.freshtocook E / CONSCRYPT: Серийный номер: 74e9c119b31c8edeb61e2c05de385e5a 2020-07-14 18: 46: 15.894 7931-8566 / com.example.freshtocook E / CONSCRYPT: SubjectDNSCRYPT: : CN = freshtocook.in 2020-07-14 18: 46: 15.895 7931-8566 / com.example.freshtocook E / CONSCRYPT: IssuerDN: CN = Secti go ЦС защищенного сервера проверки домена RSA, O = Secti go Limited, L = Salford, ST = Greater Manchester, C = GB 2020-07-14 18: 46: 15.916 7931-8566 / com.example.freshtocook E / CONSCRYPT: Получать не раньше: вс 3 мая 05:30:00 GMT + 05: 30 2020 2020-07-14 18: 46: 15.916 7931-8566 / com.example.freshtocook E / CONSCRYPT: Получать не позже: вторник 04 мая 05: 29:59 GMT + 05: 30 2021 2020-07-14 18: 46: 15.916 7931-8566 / com.example.freshtocook E / CONSCRYPT: Sig ALG имя: SHA256withRSA 2020-07-14 18: 46: 15.917 7931-8566 /com.example.freshtocook E / CONSCRYPT: Подпись: -6902f85f8676a61300badd35bbd41f6df636081e17059b9598ab32694434ec9a6366f7618241e05491a2b5a4a53ca3e48f2e4c51b381ace0056ec403e9062abd287972488ac6262709c60af3bb02b4aa3a2e966c84ed9590b1fc6f50e957681648e0fb250111741e5dad73651cb4d9efbe97acbf2a371b0ceceec9e402bdbedf2f5dfec54844a46c4946a9404ed6a9028ddf1aaed1d34dda3a09dc551916d228b4b98abaf4d3942637651b452ba7b5909b6140f3a69ad4752dbf2d64675898e40fbbe707d3ae7cb1aeb0b210fbe46b3fc949bef45179fe3bb3b9631e586cbc3f17d9c18e8b61a02cb7d5e0413f185b7f345c5612ea8b55f61d2f2340ee63e8be

1 Ответ

1 голос
/ 14 июля 2020

Вам необходимо скачать сертификат из исходного домена. просто откройте сертификат SSL и перетащите изображение в исходный каталог вашего проекта android. переименуйте и удалите расширения и '. 'точки.

мои зависимости выглядят так

dependencies {
    implementation fileTree( dir: 'libs', include: ['*.jar'] )

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    // https://mvnrepository.com/artifact/com.koushikdutta.ion/ion
    implementation group: 'com.koushikdutta.ion', name: 'ion', version: '2.2.0'



}

Я использую Ion 2.2.0 и хорошо работает с вашими неработающими изображениями.

import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;


public class MainActivity extends AppCompatActivity {

private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    img = findViewById(R.id.ntImg);


    try {


        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        // cert file stored in \app\src\main\res\raw
        InputStream caInput = getResources().openRawResource(R.raw.freshtocook);

        Certificate ca = cf.generateCertificate(caInput);
        caInput.close();

        KeyStore keyStore = KeyStore.getInstance("BKS");
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", ca);

        String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
        tmf.init(keyStore);

        TrustManager[] wrappedTrustManagers = getWrappedTrustManagers(tmf.getTrustManagers());

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, wrappedTrustManagers, null);

        AsyncSSLSocketMiddleware sslMiddleWare = Ion.getDefault(MainActivity.this).getHttpClient().getSSLSocketMiddleware();
        sslMiddleWare.setTrustManagers(wrappedTrustManagers);
        sslMiddleWare.setHostnameVerifier(getHostnameVerifier());
        sslMiddleWare.setSSLContext(sslContext);

        Ion.with(MainActivity.this)
                .load("https://freshtocook.in/uploads/banner/47a16ffc2fc5935dccd37574083c6201.jpg")
                .asBitmap()
                .setCallback(new FutureCallback<Bitmap>() {
                    @Override
                    public void onCompleted(Exception e, Bitmap bitmap) {
                        img.setImageBitmap(bitmap);
                    }
                });

    } catch (Exception e) {

    }


}


private HostnameVerifier getHostnameVerifier() {
    return new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
            // or the following:
            // HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
            // return hv.verify("www.yourserver.com", session);
        }
    };
}

private TrustManager[] getWrappedTrustManagers(TrustManager[] trustManagers) {
    final X509TrustManager originalTrustManager = (X509TrustManager) trustManagers[0];
    return new TrustManager[]{
            new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return originalTrustManager.getAcceptedIssuers();
                }

                public void checkClientTrusted(X509Certificate[] certs, String authType) {
                    try {
                        if (certs != null && certs.length > 0) {
                            certs[0].checkValidity();
                        } else {
                            originalTrustManager.checkClientTrusted(certs, authType);
                        }
                    } catch (CertificateException e) {
                        Log.w("checkClientTrusted", e.toString());
                    }
                }

                public void checkServerTrusted(X509Certificate[] certs, String authType) {
                    try {
                        if (certs != null && certs.length > 0) {
                            certs[0].checkValidity();
                        } else {
                            originalTrustManager.checkServerTrusted(certs, authType);
                        }
                    } catch (CertificateException e) {
                        Log.w("checkServerTrusted", e.toString());
                    }
                }
            }
    };
}
}

для дальнейшей поддержки мой манифест выглядит так:

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:usesCleartextTraffic="true"
    android:theme="@style/AppTheme" 
    tools:ignore="GoogleAppIndexingWarning">
    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

enter image description here drag and drop the certificate from here. Click the lock icon > view the certificate > drag and drop it to your raw folder. and remember to rename and don't leave any parts other than the name.

введите описание изображения здесь

...