gpt4 book ai didi

java - 无法通过 placeholder.com url 加载图像

转载 作者:行者123 更新时间:2023-12-04 23:52:04 27 4
gpt4 key购买 nike

遇到了一个奇怪的问题,试图从这里通过模型内部的 url 下载任何照片 -> https://jsonplaceholder.typicode.com/photos ,例如这个“https://via.placeholder.com/150/92c952”但是得到错误:

Glide: Load failed for https://via.placeholder.com/600/92c952 with size [788x788]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.io.FileNotFoundException(https://via.placeholder.com/600/92c952)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
There was 1 cause:
java.io.FileNotFoundException(https://via.placeholder.com/600/92c952)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 cause:
java.io.FileNotFoundException(https://via.placeholder.com/600/92c952)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.io.FileNotFoundException: https://via.placeholder.com/600/92c952

顺便说一句,如果我试图从其他链接加载图像,例如这个 -> https://avatars.mds.yandex.net/get-pdb/1088712/8b19d278-0b9b-46f8-89e4-66f5541efc55/s1200?webp=false

一切正常。另外我想提一下,Picasso、Fresco 等没有加载图像。使用
InputStream inputStream = new URL(urlLik).openStream();
bitmap = BitmapFactory.decodeStream(inputStream);

也无济于事。
在此先感谢,真的在这个问题上堆叠。

使用 glide 加载图像的代码:
 RequestOptions requestOptions = RequestOption.placeholderOf(R.drawable.white_background).timeout(15000)
.error(R.color.grey);
Glide.with(application)
.setDefaultRequestOptions(requestOptions).load("https://via.placeholder.com/150/92c952")
.placeholder(R.drawable.white_background).dontAnimate().into(image);

最佳答案

此问题与 User-Agent header 参数有关。和Glide无关,都是https://via.placeholder.com .您可以通过 GlideUrl 创建 URL 并添加 User-Agent header 来解决此问题。

GlideUrl url = new GlideUrl("https://your-url.com", new LazyHeaders.Builder()
.addHeader("User-Agent", "your-user-agent")
.build());

关于java - 无法通过 placeholder.com url 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62425649/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com