【问题标题】:react-native0.44, i am use fetch request "http", but network request failed?react-native0.44,我使用获取请求“http”,但网络请求失败?
【发布时间】:2018-04-14 15:46:23
【问题描述】:

我来自官方发现fetch只支持https,但是现在我用的是Mock数据,url是http,官方说如果支持http必须改info.plist,加上NSAppTransportSecurity和@ 987654329@,图片下方:

我添加App Transport Security Settings 和儿童行Allow Arbitrary Loads

请求http不支持!请问如何在 react-native 中解决 support Mock http 请求?谢谢!

我用的Mock是阿里巴巴“说唱”Mock address,只支持Mock http请求!

【问题讨论】:

  • 你能发布你的错误信息吗?
  • 错误:网络请求失败
  • 您在更改 Info.plist 后是否重新编译了您的应用程序?即重新运行react-native run-ios
  • 我从 xcode 重新启动项目,现在可以了!哈哈哈!它很奇怪!晚安!谢谢朋友!

标签: react-native


【解决方案1】:

Info.plist 将在重新编译您的应用后生效。

您可能需要通过重新运行 react-native run-ios 或从 Xcode 重新运行来重新编译您的应用程序。

【讨论】:

    【解决方案2】:

    你不应该使用NSAllowsArbitraryLoads,必须设置为false。 相反,您应该为您的域添加一个例外。

    <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>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
          <!--Include to specify minimum TLS version-->
          <key>NSTemporaryExceptionMinimumTLSVersion</key>
          <string>TLSv1.1</string>
        </dict>
      </dict>
    </dict>
    

    现在您的设备暴露在漏洞中。

    查看此post

    【讨论】:

    • 我添加了App Transport Security Setting和Allow Arbitrary Loads重启项目,没问题!你的方法应该可以解决错误!谢谢
    • 看看thisthis。您设置内容加载的方法不安全。
    猜你喜欢
    • 2017-02-10
    • 2016-03-02
    • 2021-12-06
    • 2021-04-25
    • 2022-09-24
    • 2019-01-06
    • 1970-01-01
    • 2021-04-07
    • 2020-07-23
    相关资源
    最近更新 更多