HTTPS图像无法呈现原生图像 [英] HTTPS image not rendering in react native image

查看:251
本文介绍了HTTPS图像无法呈现原生图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试渲染图像 https://www.edamam .com / web-img / 22c / 22c27bdc6b8dc67215c7478cb4e5dc42.jpg 在网络浏览器中工作正常,但在反应原生图像中,图像不会出现。

I am trying to render an image "https://www.edamam.com/web-img/22c/22c27bdc6b8dc67215c7478cb4e5dc42.jpg" which works fine in a web browser, but in a react-native image the image does not appear.

我正在尝试:

<Image style={{height: 200, width: 200}} source={{uri:'https://www.edamam.com/web-img/22c/22c27bdc6b8dc67215c7478cb4e5dc42.jpg'}}/>

这也不起作用:

<Image style={{flex: 1, resizeMode: 'cover'}} source={{uri:'https://www.edamam.com/web-img/22c/22c27bdc6b8dc67215c7478cb4e5dc42.jpg'}}/>

我在这里做错了什么?

推荐答案

我尝试了你的代码,最初我没有得到图像,然后我使用 onError 处理程序处理错误,发现以下错误

I tried your code, initially I did not get the image, then I handle the error using onError handler and found the following error


发生了SSL错误,无法与服务器建立安全连接

An SSL error has occurred and a secure connection to the server cannot be made

您可以查看此错误的stackoverflow答案这里

You may look into the stackoverflow answers for this error here

我通过更改


info.plist

info.plist

具有以下配置且工作正常

with following configuration and it worked

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

查看这个文档,上述方法 不推荐 ,相反,他们建议采用其他方式(在链接的stackoverflow答案中也会提到)。

Have a look into this document, above approach is not recommended, instead they have suggested other way (it is also mentioned in the linked stackoverflow answer).

希望这会有所帮助。

这篇关于HTTPS图像无法呈现原生图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆