gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 04:45:10 26 4
gpt4 key购买 nike

我正在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com