android - 如何从重定向到 https 的 http URL 下载图像?

标签 android picasso

我花了几天时间尝试让它工作,但仍然没有成功。 我的问题是 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

what JakeWharton solution for this

关于android - 如何从重定向到 https 的 http URL 下载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42527553/

相关文章:

android - 查看寻呼机垂直重叠选项卡 fragment

android - 为什么我的广播接收器无法识别我的字符串 - 发送短信代码

java - BaseAdapter 和 Picasso 问题

java - 为什么图像保存不再适用于 API 29

android - 无法在 recyclerview 中加载来自 picasso 的图像?

java - picasso 图像无法加载

Android PagedList 更新

java - Android 约束布局编辑器问题

android - 卸载时获取包(应用程序)版本名称

安卓|在哪里存储运行时从服务器获取的图像