如何在 React Native XMLHttpRequest API 或 Fetch Api 中禁用 ssl 检查?

Shi*_*hew 4 ssl xmlhttprequest react-native fetch-api

在本地测试服务器 url 上有 ssl 证书错误,所以我必须禁用 ssl 检查。我在stackoverflow上阅读了许多解决方案,但没有一个有帮助。问题是我无法在服务器上进行任何更改。所以我想知道如何禁用 ssl 检查,或者是否有任何其他 api,例如 fetch api 或 Retrofit for react native。?
我的 fetch api 代码如下

fetch('https://example.com/logincheck', {
  method: 'post',
  headers: {
    'Accept': 'application/json, text/plain,',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "username" :"usrname",
  })
})
  .then(response =>  response.json())
  .then(responseobj => {
    this.setState({

    });
    console.log("login status:",responseobj.success);


  })
  .catch((error) => {
      console.error(error);
    });
Run Code Online (Sandbox Code Playgroud)

Shi*_*hew 7

现在绕过 ssl 证书问题.. rn-fetch-blob 发布。任何搜索更新答案的人请使用此答案并检查

rn-fetch-blob

包裹。使用自签名认证连接服务器,需要显式添加trusty到config

RNFetchBlob.config({
  trusty : true
})
.fetch('GET', 'https://example.com')
.then((resp) => {
  // ...
})
Run Code Online (Sandbox Code Playgroud)