且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

React Native应用如何想访问HTTP资源应该怎么办

更新时间:2022-09-13 11:59:31

React Native应用如何想访问HTTP资源应该怎么办Network Request Failed。


Google了一下,在***上发现其他网友也遇到类似问题:


https://***.com/questions/38418998/react-native-fetch-network-request-failed


React Native应用如何想访问HTTP资源应该怎么办网友回复说iOS默认不允许HTTP请求,只允许HTTPS。如果想用HTTP,需要在info.plist里加入下面信息:


<key>NSAppTransportSecurity</key>

<dict>

  <key>NSAllowsArbitraryLoads</key>

  <true/>

</dict>

<key>NSAppTransportSecurity</key>

<dict>

 <key>NSExceptionDomains</key>

 <dict>

  <key>yourserver.com</key>

  <dict>

   <!--Include to allow subdomains-->

   <key>NSIncludesSubdomains</key>

   <true/>

   <!--Include to allow HTTP requests-->

   <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>

   <true/>

   <!--Include to specify minimum TLS version-->

   <key>NSTemporaryExceptionMinimumTLSVersion</key>

   <string>TLSv1.1</string>

  </dict>

 </dict>

</dict>

详细信息参考React Native的官网:

https://facebook.github.io/react-native/docs/integration-with-existing-apps.html#test-your-integration