react native中的fetch方法必须请求https吗?请求http不行吗?



  •   各位亲,我在用mockjs模拟数据的时候发现fetch方法如果发起http请求的话就会出现“网络请求失败(network request failed)”,只有请求https才会请求成功。之前的<Image source={{uri:https://.......}}></Image>中的uri也必须是https,使用http请求不行吗?为什么?这给我mock假数据带来了很大的不便,大家有谁了解这一块吗?希望有哪位大神能帮我解答这个问题!谢谢大家🙏!


  • 有哪位大神能够告诉我原因吗?



  • ios要改安全设置
    查一下吧



  • 在 Info.plist 里使用:

    <key>NSAppTransportSecurity</key>
    <dict>
    	<key>NSAllowsArbitraryLoads</key>
    	<true/>
    	<key>NSExceptionDomains</key>
    	<dict>
    		<key>localhost</key>
    		<dict>
    			<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
    			<true/>
    		</dict>
    	</dict>
    </dict>
    

    By default, iOS will block any request that's not encrypted using SSL. If you need to fetch from a cleartext URL (one that begins with http) you will first need to add an App Transport Security exception. If you know ahead of time what domains you will need access to, it is more secure to add exceptions just for those domains; if the domains are not known until runtime you can disable ATS completely. See Apple's documentation for more information.



  • @zhiquan_yu Thank you so much!