【问题标题】:Ignore Ssl Certificate Verification in react native在本机反应中忽略 SSL 证书验证
【发布时间】:2018-03-25 13:40:56
【问题描述】:
我正在开发一个应用程序,该应用程序使用 rest API 将其连接到数据库,并且我的服务器具有 SSL 证书,并且当我尝试发送请求时,它从我的 react 本机应用程序中显示error msg 是否存在一种在 react native for android 中禁用 SSL 验证的方法。
如果有人知道,请帮忙。
【问题讨论】:
标签:
android
ssl
react-native
ssl-certificate
fetch
【解决方案1】:
这个解决方案在 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()