okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Okhttp can not load images from https Url . What can I do ?

Open mehmeth opened this issue 8 years ago • 2 comments

I am using Picasso for downloading images from my server.When server communication is http there is no problem. I can get my images from server.

But whenever I change my Url to https picasso can not send request to server. With the https other parts of the application works. I can send https requests and can take responses from the server. Only my problem is with the images.

Note: I am using self-signed certificate

My build.gradle file consists following parts;

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

This is my code for Picasso

private static OkHttpClient getDownloader(){
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request newRequest = chain.request().newBuilder()
                                .addHeader("token", LocalStorage.getUserToken(ImageDisplay.ctx))
                                .build();
                        return chain.proceed(newRequest);
                    }
                })
                .build();
        return client;
    }

public static boolean isInited(){
    return ImageLoader.getInstance().isInited();
}

public static void init(final Context context){
    ImageDisplay.ctx = context;

    if(memcache == null){
        memcache = new Cache() {
            LruMemoryCache c = new LruMemoryCache((int)getMemorySizeForCache(context));
            @Override
            public Bitmap get(String key) {
                return c.get(key);
            }

            @Override
            public void set(String key, Bitmap bitmap) {
                c.put(key, bitmap);
            }

            @Override
            public int size() {
                return c.keys().size();
            }

            @Override
            public int maxSize() {
                return size;
            }

            @Override
            public void clear() {
                c.clear();
            }

            @Override
            public void clearKeyUri(String keyPrefix) {
                c.remove(keyPrefix);
            }
        };
    }

    Map<String,String> authHeaders = new HashMap<>();
    authHeaders.put("token", LocalStorage.getUserToken(ctx));

    ImageLoaderConfiguration.Builder configsBuilder = new ImageLoaderConfiguration.Builder(ctx)
            .imageDownloader(new AuthImageDownloader(ctx))
            .defaultDisplayImageOptions(defaults);
    ImageLoader.getInstance().init(configsBuilder.build());

   
    pcs = new Picasso.Builder(context).memoryCache(memcache)
            // .indicatorsEnabled(true)
            .downloader(new OkHttp3Downloader(getDownloader()))
            .build();

    pcsNoCache = new Picasso.Builder(context)
            // .indicatorsEnabled(true)
            .downloader(new OkHttp3Downloader(getDownloader()))
            .build();

With the following line I can not send request to https

pcsNoCache.load(url).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(view);

Can you please help me ? Thanks a lot.

mehmeth avatar Mar 19 '18 12:03 mehmeth

Thanks for your question. This issue tracker is only for bug reports with test cases and feature requests. Please ask usage questions on Stack Overflow. https://stackoverflow.com/questions/tagged/okhttp

swankjesse avatar Mar 19 '18 14:03 swankjesse

@swankjesse If you know the answer , Can you help me in the stackoverflow ? I am new to Android and need help

https://stackoverflow.com/questions/49360985/android-picasso-can-not-send-request-to-https-urls

mehmeth avatar Mar 19 '18 14:03 mehmeth