javascript - 如何在 react-native 中禁用 ssl 证书验证
问题描述
我正在用 react-native 构建一个应用程序。我正在尝试使用 fetch 方法在 react-native 中使用 API。SSL 证书验证在关闭时会从 API 给出响应,否则会显示“无响应”。有没有办法在 react-native 中禁用 SSL 证书验证?下面是我点击 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())
});
解决方案
您将 fetch 的两个参数的括号合为一个,请考虑以下内容
fetch('https://slimparts.cap-tek.com:8080/v1/make', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
})
.then((response) => response.json())
.then((responseJson) => {
console.log(JSON.stringify(responseJson))
})
.catch((err) => {
console.log(err.toString())
});
推荐阅读
- javascript - Firebase Analytics 是否可以在 Cordova 上完全运行(没有任何 cordova 插件)?
- linux - 如何在 Docker 容器中为 Alpine Linux 构建 APK?
- javascript - Nuxt/Buefy -
组件显示不一致 - react-native - 无法使用 react-native-beacons-manager 检测 Android 中的 ibeacons
- bash - 如何为每个唯一字符串添加值?
- php - Symfony 教义错误“DoctrineMigrationsBundle 需要启用 DoctrineBundle。”
- flutter - 如何在颤动的提要屏幕中将照片和视频一起添加
- algorithm - 如何使用 union-find 方法解决 Manager peer 问题?
- java - 绘画程序JavaFX中的线条绘画
- javascript - 如何将复选框中的值作为分组参数添加到 URL 字符串?