React Native应用如何想访问HTTP资源应该怎么办
生活随笔
收集整理的這篇文章主要介紹了
React Native应用如何想访问HTTP资源应该怎么办
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
當我使用JavaScript fetch API訪問http資源時,遇到一個錯誤:
Network Request Failed。
Google了一下,在stackoverflow上發現其他網友也遇到類似問題:
https://stackoverflow.com/questions/38418998/react-native-fetch-network-request-failed
網友回復說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
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的React Native应用如何想访问HTTP资源应该怎么办的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 消息称华为考虑在沙特阿拉伯设中东总部
- 下一篇: HTTPS和TCP的关系