Com. Bumptech. Glide. Load. Httpexception: Forbidden

Com. Bumptech. Glide. Load. Httpexception: Forbidden

I want to use glide to load a url picture

GlideApp.with(this).load("").error(R.mipmap.ic_launcher).into(photoView);

but it catch error:

class com.bumptech.glide.load.engine.GlideException: Failed to load resource
08-14 00:59:32.323 15273-15273/com.yaminet.yami I/Glide: Root cause (1 of 1)
                                                     com.bumptech.glide.load.HttpException: Forbidden
                                                         at  com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:118)
                                                         at  com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:53)
                                                         at  com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:95)
                                                         at  com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:144)
                                                         at  com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:138)
                                                         at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59)
                                                         at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:95)
                                                         at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:61)
                                                         at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:282)
                                                         at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:252)
                                                         at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:222)
                                                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                         at java.lang.Thread.run(Thread.java:761)
                                                         at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:347)

How can I load the big picture from the Internet with glide ?

3

1 Answer

I also have this error today, because I have used yande's api many times, so, I think maybe this has two possible reason, one is in one time the glide have many request so that the yande serve refuses to responce, the second one is that if you use spider to show yande's picture, you need make your spider like a Internet Expore, use some methods like add headers to http request.

In my code, I add headers, it was solved.

    pictureItem = (PictureItem) getIntent().getExtras().get("PictureItem");
    image = (ImageView) findViewById(R.id.image);

    GlideUrl glideUrl = new GlideUrl(pictureItem.sample_url, new LazyHeaders.Builder()
            .addHeader("User-Agent",
                    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit / 537.36(KHTML, like Gecko) Chrome  47.0.2526.106 Safari / 537.36")
            .build());

    Glide.with(this)
         .load(glideUrl)
         .into(image);

some reference which may help you:

Glide - adding header to request

Yande API

Any way, if we write some code like spider, we should think more about the website we get info from. (smile face)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.