javascript - 如何在 react-native 中禁用 ssl 证书验证

标签 javascript node.js 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 - 如何在 react-native 中禁用 ssl 证书验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57006337/

相关文章:

javascript - 需要 if else 语句的助手

javascript - 使用 History.js 进行 axax。效果很好,但我对用户回击重新输入我的应用程序时发生的情况感到困惑

javascript - ES 6 - 使用类

ios - 在 'passwordRules' 类型的对象上找不到属性 'UIView<RCTBackedTextInputViewProtocol> *'

javascript - 从文本框中获取整数值,如何检查它是 NaN 还是 null 等?

javascript - React Native 在获取数据完成后从 Promise 中获取值

mysql - node/mysql查询多次返回相同的行:

javascript - 在 Mocha 中使用 Sinon 读取断言控制台消息

javascript - react native : Why don't flex justifyContent and alignItems work for child <View/>?

react-native - 呈现 UI 但除非触摸,否则不会绘制屏幕