如何解决 react native tls/ssl 网络错误?
How solve react native tls/ssl network error?
我使用 graphql 服务器(在 graphql-yoga 库中)。
我将 openssl 命令创建的证书应用到 'https' 选项。
然后我使用 'https' 协议通过 pc chrome 浏览器连接 graphql-playground。
它运行良好。
但它不适用于使用 react-native 制作的应用程序。
它使用 apollo-boost 库中的 apollo 客户端。
并且我在 ApolloClient
构造函数选项 uri 字段中应用了测试服务器地址 'https://192.168.0.4:4001'。
应用程序再次给我网络错误!
WARN Possible Unhandled Promise Rejection (id: 1):
Error: Network error: Network request failed
ApolloError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:102209:32
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103704:51
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:104124:25
forEach@[native code]
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:104122:35
forEach@[native code]
broadcastQueries@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:104120:29
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103599:47
tryCallOne@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27024:16
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27125:27
_callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30579:17
_callImmediatesPass@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30615:19
callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30834:33
callImmediates@[native code]
__callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2591:35
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2368:34
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2574:15
flushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2367:21
flushedQueue@[native code]
callFunctionReturnFlushedQueue@[native code]
请让我知道这个问题的解决方案。
是的,我自己解决了我的问题。
在我的例子中,它必须检查两件事。
首先,您必须使用授权认证,而不是自签认证。
(我觉得React Native强制使用授权认证。)
(所以我使用了'Let`s encrypt'的认证)
其次,您必须在 'httpsOption' 对象(在任何 graphQLServer 中)中记录 'ca' 选项(字段)。
就我而言,我没有记录 'ca' 选项。
所以我记录了'ca'选项,'ca'文件路径,它工作正常。
(必须在'httpsOption'中记录密钥、证书和ca选项)
我使用 axios 找到因果关系。
我编写了 graphQL 查询并使用 axios 发送了它。
axios 请报告错误。不像 apolloClient.
...来自大韩民国。
我使用 graphql 服务器(在 graphql-yoga 库中)。
我将 openssl 命令创建的证书应用到 'https' 选项。
然后我使用 'https' 协议通过 pc chrome 浏览器连接 graphql-playground。
它运行良好。
但它不适用于使用 react-native 制作的应用程序。
它使用 apollo-boost 库中的 apollo 客户端。
并且我在 ApolloClient
构造函数选项 uri 字段中应用了测试服务器地址 'https://192.168.0.4:4001'。
应用程序再次给我网络错误!
WARN Possible Unhandled Promise Rejection (id: 1):
Error: Network error: Network request failed
ApolloError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:102209:32
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103704:51
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:104124:25
forEach@[native code]
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:104122:35
forEach@[native code]
broadcastQueries@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:104120:29
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103599:47
tryCallOne@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27024:16
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27125:27
_callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30579:17
_callImmediatesPass@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30615:19
callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30834:33
callImmediates@[native code]
__callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2591:35
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2368:34
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2574:15
flushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2367:21
flushedQueue@[native code]
callFunctionReturnFlushedQueue@[native code]
请让我知道这个问题的解决方案。
是的,我自己解决了我的问题。
在我的例子中,它必须检查两件事。
首先,您必须使用授权认证,而不是自签认证。
(我觉得React Native强制使用授权认证。)
(所以我使用了'Let`s encrypt'的认证)
其次,您必须在 'httpsOption' 对象(在任何 graphQLServer 中)中记录 'ca' 选项(字段)。
就我而言,我没有记录 'ca' 选项。
所以我记录了'ca'选项,'ca'文件路径,它工作正常。
(必须在'httpsOption'中记录密钥、证书和ca选项)
我使用 axios 找到因果关系。
我编写了 graphQL 查询并使用 axios 发送了它。
axios 请报告错误。不像 apolloClient.
...来自大韩民国。