【发布时间】:2019-07-12 11:43:42
【问题描述】:
我正在用 react-native 构建一个应用程序。我正在尝试使用 fetch 方法在 react-native 中使用 API。 SSL 证书验证在关闭时会从 API 发出响应,否则会显示“无响应”。有没有办法在 react-native 中禁用 SSL 证书验证? 下面是我的代码 sn-p 用于访问 API。
fetch(('https:www.myUrl.com',{
method: 'GET',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json',
},
}))
.then((response) => response.json())
.then((responseJson) => {
console.log(JSON.stringify(responseJson))
})
.catch((err) => {
Alert.alert("Request Failed")
console.log(err.toString())
});
【问题讨论】:
-
“有没有办法在 react-native 中禁用 SSL 证书验证?”这不是一个好主意,您几乎失去了 HTTPS 的所有好处。您不妨改为使用明文 HTTP...
-
@PatrickMevzek 我试过了,还是不行
标签: javascript node.js react-native ssl