在React Native中忽略SSL证书验证

4
我正在开发一个使用rest API连接到数据库的应用程序,我的服务器有一个SSL证书。当我尝试从我的react native应用程序发送请求时,它显示了这个错误消息(链接在此 error msg)。是否有办法在Android上禁用react native中的SSL验证?如果有,希望能得到帮助。

我认为你可以参考这个问题 - Alexander Vitanov
1个回答

2
这个解决方案适用于Android:
安装包:npm install --save rn-fetch-blob
将以下代码粘贴到您的index.js文件中。
import RNFetchBlob from 'rn-fetch-blob';

AppRegistry.registerComponent(appName, () => App);
const Fetch = RNFetchBlob.polyfill.Fetch
  // replace built-in fetch
 window.fetch = new Fetch({
 // enable this option so that the response data conversion handled automatically
  auto : true,
  // when receiving response data, the module will match its Content-Type header
  // with strings in this array. If it contains any one of string in this array, 
 // the response body will be considered as binary data and the data will be stored
 // in file system instead of in memory.
 // By default, it only store response data to file system when Content-Type 
 // contains string `application/octet`.
  binaryContentTypes : [
  'image/',
  'video/',
  'audio/',
  'foo/',
   ],
   trusty : true
  }).build()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接