简体   繁体   中英

Glide load an image from an URl

I'm trying to use Glide to load an image from an Url:

Glide.with(getContext()).load(urlImage).error(R.drawable.ic_profile_default).into(imgUser);

This is the error I get:

W/Glide: Load failed for https:www.cerberusenlinea.com/images/profile/16/13/HOLCIM.jpeg with size [204x204]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There was 1 cause:
    javax.net.ssl.SSLHandshakeException(java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.)
     call GlideException#logRootCauses(String) for more detail

The problem is that you are trying to take the image from a not secure website, so glide blocks you. To solve this issue you can create a custom trust manager but is very dangerous because you get exposed to man in the middle attack. If you want to follow this route i suggest you to read this Trust Anchor not found for Android SSL Connection

Another work around solution, that i suggest could be download the image and host it on your server or on a free service (you can found a lot of them) like https://imgur.com/upload or everyone else

The HTTPS configuration for the site www.cerberusenlinea.com has chain issues.

You can verify it in the Qualys Free Scanner: https://www.ssllabs.com/ssltest/analyze.html?d=www.cerberusenlinea.com

结果质量扫描仪

Android requires the full certificate chain in order to consume the content.

The official documentation says:

Most public CAs don't sign server certificates directly. Instead, they use their main CA certificate, referred to as the root CA, to sign intermediate CAs. They do this so the root CA can be stored offline to reduce risk of compromise. However, operating systems like Android typically trust only root CAs directly, which leaves a short gap of trust between the server certificate—signed by the intermediate CA—and the certificate verifier, which knows the root CA. To solve this, the server doesn't send the client only it's certificate during the SSL handshake, but a chain of certificates from the server CA through any intermediates necessary to reach a trusted root CA.

The documentation mention some alternatives in order to address the problem from the application side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM