Picasso http urldan rasm yuklamaydi, lekin http urlidan rasmlarni yuklaydi?

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

saytning HTTPS versiyasiga havolani keltirib chiqaradi va faqat xato beradi

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)

Ammo yuqoridagi kodlar OkHttpDownloaderni hal qila olmaydi

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?

2
picasso.with (bu) .load (current.getImageURL ()) kirib ( ImageVie & zwnj; w ). Bu yerda ImageView siz ob'ekt yoki sinf nomi >> hisoblanadi
qo'shib qo'ydi muallif Dharmbir Singh, manba
Ob'ekt
qo'shib qo'ydi muallif knight, manba

6 javoblar

HTTPSni HTTPS da https bilan o'zgartiring. Ushbu kodni sinab ko'ring.

String aUrl = aImageInfo.getImage_url().replace("http", "https");

    Picasso
            .with(myContext)
            .load(aUrl)
            .placeholder(R.mipmap.place_holder)
            .error(R.mipmap.error)
            .fit()
            .into(aHolder.aImageView);
1
qo'shib qo'ydi
Yaxshi! Men bir oz kuldim, chunki bu erda Picasso kutubxonasi orqali nimalar bo'layotganini ko'rish uchun kelganimga keldim, keyin sizning javobingizni ko'rdim va men "OK, menimcha, bu yechim" kabi edi :))
qo'shib qo'ydi muallif sunlover3, manba
hmm bu ishlamaydi, chunki butun muammo shunda hal bo'lmaydigan HTTPSni ishlatishga majbur bo'ldi, mening saytda SSL yo'q, chunki uni http'dan foydalanishga majbur qilish kerak.
qo'shib qo'ydi muallif knight, manba

Picasso sukut bo'yicha UrlConnectionDownloader foydalanadi. Undan HTTP dan HTTPS (yoki aksincha) ga avtomatik ravishda yo'naltirilmaydigan HttpURLConnection dan foydalanishni tushunishingiz mumkin. Yo'nalishni keyinchalik jiddiy xavfsizlik oqibatlariga olib kelishi mumkin.

Buning oldini olish uchun OkHttp3Downloader - Picasso 2 uchun OkHttp 3 downloader dasturini ishlatishdir.

OkHttpClient client = new OkHttpClient(); 
Picasso picasso = new Picasso.Builder(context)
.downloader(new OkHttp3Downloader(client))
.build()

OkHttp3Downloader dan foydalanish uchun qaramlikni kiritish kerak

compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
0
qo'shib qo'ydi

Sizning urlingiz HTTPS ni o'z ichiga oladi, shunda urlda https-ni ishlatishingiz kerak bo'ladi, aks holda u yuklamaydi, siz ham an'anaviy http bilan rasmni yuklab bo'lolmaysiz. BitmapFactory yordamida http rasmini yuklab olishni sinashni istasangiz.

Rahmat.

0
qo'shib qo'ydi
Yo'q, brauzerda uning http-ga https avtomatik ravishda yo'naltiriladi, ammo dasturiy ittifoqdagina https-ni o'rnatishimiz kerak.
qo'shib qo'ydi muallif Jd Prajapati, manba
Shunday qilib, http-dan foydalanish mumkin emasmi?
qo'shib qo'ydi muallif knight, manba

Agar siz Picassodan qayta qo'ng'iroq qilishni xohlasangiz, quyidagilarni tekshirib ko'ring va onBitmapLoaded() bitmapni ImageView-ga sozlang

Picasso.with(getContext()).load(url).into(new Target() {
    @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
       //cache is now warmed up
    }
    @Override public void onBitmapFailed(Drawable errorDrawable) { }
    @Override public void onPrepareLoad(Drawable placeHolderDrawable) { }
});
0
qo'shib qo'ydi

buni sizning ilova sinfiga qo'shishingiz mumkin:

    final OkHttpClient client = new OkHttpClient.Builder()
            .protocols(Collections.singletonList(Protocol.HTTP_1_1))
            .build();

    final Picasso picasso = new Picasso.Builder(this)
            .downloader(new OkHttp3Downloader(client))
            .build();

    Picasso.setSingletonInstance(picasso);
0
qo'shib qo'ydi

CustomPicasso.java

import android.content.Context;
import android.util.Log;

import com.jakewharton.picasso.OkHttp3Downloader;
import com.squareup.picasso.Picasso;

/**
 * Created by Hrishikesh Kadam on 19/12/2017
 */

public class CustomPicasso {

    private static String LOG_TAG = CustomPicasso.class.getSimpleName();
    private static boolean hasCustomPicassoSingletonInstanceSet;

    public static Picasso with(Context context) {

        if (hasCustomPicassoSingletonInstanceSet)
            return Picasso.with(context);

        try {
            Picasso.setSingletonInstance(null);
        } catch (IllegalStateException e) {
            Log.w(LOG_TAG, "-> Default singleton instance already present" +
                    " so CustomPicasso singleton cannot be set. Use CustomPicasso.getNewInstance() now.");
            return Picasso.with(context);
        }

        Picasso picasso = new Picasso.Builder(context).
                downloader(new OkHttp3Downloader(context))
                .build();

        Picasso.setSingletonInstance(picasso);
        Log.w(LOG_TAG, "-> CustomPicasso singleton set to Picasso singleton." +
                " In case if you need Picasso singleton in future then use Picasso.Builder()");
        hasCustomPicassoSingletonInstanceSet = true;

        return picasso;
    }

    public static Picasso getNewInstance(Context context) {

        Log.w(LOG_TAG, "-> Do not forget to call customPicasso.shutdown()" +
                " to avoid memory leak");

        return new Picasso.Builder(context).
                downloader(new OkHttp3Downloader(context))
                .build();
    }
}

build.gradle (Module: ilova)

android {

    ...

}

dependencies {

    ...

    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
}

Foydalanish -

CustomPicasso.with(context)
    .load("http://i.imgur.com/DvpvklR.png")
    .into(imageView);
0
qo'shib qo'ydi