Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
832 views
in Technique[技术] by (71.8m points)

android - Picasso not loading image from http url but loads images from https url?

Picasso Loads the image fine if its from a https url like: https://i.ytimg.com/vi/28uUsJ72a1A/hqdefault.jpg

Since youtube directs all traffic through https this works to: http://i.ytimg.com/vi/28uUsJ72a1A/hqdefault.jpg

But when I use my url http://www.example.com/images/djnsdfndsf.jpg

it redircets the link to a https version of the site and just gives a error

This is how i'm loading the images Picasso.with(this).load(current.getImageURL()).into(ImageView);

So I tried using this:
//Below code for Picasso initializing once for the app
private Picasso picasso;
private OkHttpClient okHttpClient;

okHttpClient = new OkHttpClient();
picasso = new Picasso.Builder(this)
                .downloader(new OkHttpDownloader(okHttpClient))
                .build();

//Below code to retrieve the images whereever required on the app
picasso.with(this).load(current.getImageURL()).into(imageView)

But Above code gives cannot resolve OkHttpDownloader

Right Now I'm using compile 'com.squareup.picasso:picasso:2.5.2'

EDIT How do I force Picasso to download it over http not https?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

HTTP requests are not allowed in API level 28+. To specifically allow HTTP requests to your domain, you must add the following file to your code.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">riafy.me</domain>       
</domain-config>
</network-security-config>

Add your domain name replacing riafy.me and add this file as network_security_config.xml in xml folder in resources.

android:networkSecurityConfig="@xml/network_security_config"

Add this to application tag in your manifest file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...