javaandroidhttpokhttpfresco

Android Fresco SimpleDraweeView.setImageURI not working for this http url


mySimpleDraweeView.setImageURI(Uri.parse("http://cdn.cnn.com:80/cnn/.e1mo/img/4.0/logos/menu_politics.png"));

This is a url from link preview for cnn. It is an http url and not an https url. It has a port :80 in the path.

If I throw that url into a webbrowser, it gets resolved as "http://cdn.cnn.com/cnn/.e1mo/img/4.0/logos/menu_politics.png" and an image is there.

If I try to call setImageURI with "http://cdn.cnn.com/cnn/.e1mo/img/4.0/logos/menu_politics.png" from the web browser, it still doesn't work.

If I try to call setImageURI with "https://cdn.cnn.com/cnn/.e1mo/img/4.0/logos/menu_politics.png" it works.

I'm using a custom OKHttp3 OkHttpClient for Fresco. I tried using the getUnsafeOkHttpClient described here https://stackoverflow.com/a/25992879/1578222, but did not see a change in behavior with it.

I also tried setting the OkHttpClient.followRedirects but it did not fix it either:

httpClient.followSslRedirects(true);
httpClient.followRedirects(true);

Solution

  • I found a log message from the OKHttp3 client and that helped me figure out the problem:

    <-- HTTP FAILED: java.net.UnknownServiceException: CLEARTEXT communication to cdn.cnn.com not permitted by network security policy

    Solved my changing the Android Manifest file's Application object to include:

    android:usesCleartextTraffic="true"