问题描述
我想使用滑行加载url图片
I want to use glide to load a url picture
GlideApp.with(this).load("https://files.yande.re/image/0f1c68aa6d34fb3a7a7af855e0036377/yande.re%20404988%20arsenixc%20landscape.jpg").error(R.mipmap.ic_launcher).into(photoView);
但它捕获了错误:
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)
如何通过滑行从Internet加载大图景?
How can I load the big picture from the Internet with glide ?
推荐答案
我今天也遇到此错误,因为我已经多次使用yande的api,所以,我认为这可能有两个可能的原因,一个是一次glide有很多要求,因此yande服务拒绝响应,第二个要求是,如果您使用Spider来显示yande的图片,则需要使您的Spider像Internet Expre一样,使用一些方法,例如将标头添加到http请求中.
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);
一些参考可以帮助您:
无论如何,如果我们编写诸如Spider之类的代码,我们应该更多地考虑从中获取信息的网站. (笑脸)
Any way, if we write some code like spider, we should think more about the website we get info from. (smile face)
这篇关于com.bumptech.glide.load.HttpException:禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!