在使用react native请求数据时,完全可以不用考虑跨域的问题直接填写要获取的地址就可以。
但是在用react native开发时候默认情况下是只能支持https请求的,就是说http请求的地址会提示失败,Network Request Failed。
这时候我们需要修改我们的项目配置文件,打开/ios/项目名/Info.plist,将原来的内容:
<key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>localhost</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> </dict> </dict> </dict>
修改为 :
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
http://stackoverflow.com/questions/38418998/react-native-fetch-network-request-failed