我花了几天时间尝试让它工作,但仍然没有成功。
我的问题是 url 出于某种原因重定向到 https
版本
假设这是图片 url:
http://api.androidhive.info/images/sample.jpg
由于某种原因,图像重定向到 https,例如:
https://api.androidhive.info/images/sample.jpg
由于我的网站没有 https,因此:
"This site can’t be reached"
然后没有图片被下载
我已遵循本教程 link
我正在使用 Picasso 从 youtube 工作的所有 https url 加载图像但是当我调用没有 https 的 url 时它不起作用
这是我用的安卓版本
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.example.example"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
我不知道该怎么做任何帮助都会很棒。
最佳答案
以下只是您可以做的变通或破解,
In the callback of Picasso do this:
//this is the url which is having https
String url = "https://api.androidhive.info/images/sample.jpg";
//in callback of picasso which is overriden when some error occurs do this steps
String newUrl = url.replace("https", "http");
Picasso.with(context)
.load(newUrl)
.into(imageView);
这只是一种解决方法
If this way around is not working follow this link
关于android - 如何从重定向到 https 的 http URL 下载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42527553/