ios - React Native 获取网络请求失败 iOS

标签 ios facebook post react-native

我正在尝试使用 fetch 向 Facebook Graph API 发送 GET 请求:

var url = "https://graph.facebook.com/v2.7/"
+FACEBOOK_APP_ID
+"?fields=context"
+"{friends_using_app{id,name,picture.type(normal)}}"
+"&access_token="+_this.props.user.facebook_access_token;

fetch(url)
.then((response) => response.json())
.then((responseJson) => {
  console.log(responseJson);
})
.catch(function(error) {
  console.log(error);
});

但我在 JavaScript 控制台中收到 TypeError: Network request failed(…)这只发生在 iOS 上,在 Android 上运行良好。

据我所知,iOS on react native 默认允许 HTTPS 请求,所以这应该不需要任何配置。

我可以向 https://google.com 提出请求使用 fetch,当我打印 url var 并直接粘贴时,我能够在 safari 中查看上述请求的结果。

似乎找不到任何类似的东西,但很抱歉,如果这是重复的。

最佳答案

As far as I know, iOS on react native allows HTTPS requests by default, so this shouldn't require any config.

这不太对。对于 App Transport Security,任何旧的 https 连接都不够好,因此您可能仍需要进行一些配置。这是 the docs关于在没有配置的情况下满足 ATS 的确切要求:

With ATS fully enabled, your app’s HTTP connections must use HTTPS and must satisfy the following security requirements:

The server certificate must meet at least one of the following trust requirements: Issued by a certificate authority (CA) whose root certificate is incorporated into the operating system Issued by a trusted root CA and installed by the user or a system administrator The negotiated Transport Layer Security version must be TLS 1.2 The negotiated TLS connection cipher suite must support forward secrecy (FS) and be one of the following: TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA The leaf server certificate must be signed with one of the following types of keys: Rivest-Shamir-Adleman (RSA) key with a length of at least 2048 bits Elliptic-Curve Cryptography (ECC) key with a size of at least 256 bits In addition, the leaf server certificate hashing algorithm must be Secure Hash Algorithm 2 (SHA-2) with a digest length of at least 256 (that is, SHA-256 or greater). If ATS is not enabled, the system still performs HTTPS server trust evaluation but you can override it on a case-by-case basis, as described in HTTPS Server Trust Evaluation. With ATS fully enabled, you cannot override the default HTTPS server trust evaluation.

The requirements listed in this section are current as of this document’s publication date, with stricter requirements possible in the future. Changes to these requirements will not break app binary compatibility.

我还创建了一个视频教程,介绍如何为您的 React native 应用发出网络请求:http://codecookbook.co/post/how-to-make-network-requests-in-react-native/

关于ios - React Native 获取网络请求失败 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39142795/

相关文章:

javascript - 如果用户未登录则重定向页面

ios - 如果用户在登录后更改了他的 facebook 个人资料详细信息,如何在我的应用程序中更新 facebook 个人资料?

java - JSOUP 登录失败

ios - 使用 UIwebview 使用 swift 从库中附加照片

ios - 如何使用 AFOAuth2Manager 自动刷新过期的 token ?

ios - Phonegap/Cordova 在 ios8 中不工作

iphone - Facebook iOS 授权并在没有对话的情况下发布?

php - 在php中将数据从新窗口发送到上一个窗口

http - 将表单 POST 与查询字符串组合是否有效?

android - 无法通过节点终端向 phonegap 应用程序发送推送通知