如何在React Native XMLHttpRequest API或Fetch Api中禁用ssl检查? [英] How to disable ssl check in react native XMLHttpRequest API or in Fetch Api?

查看:54
本文介绍了如何在React Native XMLHttpRequest API或Fetch Api中禁用ssl检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地测试服务器上,URL具有ssl证书错误,因此我必须禁用ssl检查.我已经阅读了许多关于stackoverflow的解决方案,但都无济于事.问题是我无法在服务器上进行任何更改.所以我想知道如何禁用ssl检查,或者是否有其他其他api,例如fetch api或Retrofit来进行本机反应??
我的提取api代码如下

On local testing server url have ssl certificate error so i have to disable ssl check. I have read many solutions on stackoverflow none of them helped. Problem is i can't make any change on server. So i want to know how to disable ssl check or is there any other api like fetch api or Retrofit for react native.?
My fetch api code as follows

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);
    });

推荐答案

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

Now to bypass ssl certificate issue.. rn-fetch-blob released. Anyone searching for updated answer please use this answer and check the

rn-fetch-blob

rn-fetch-blob

包.要使用自签名证书连接服务器,您需要显式添加可信任的配置

package. To connect a server with self-signed certification, you need to add trusty to config explicitly

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

这篇关于如何在React Native XMLHttpRequest API或Fetch Api中禁用ssl检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆