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

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

问题描述

在本地测试服务器 url 上有 ssl 证书错误,所以我必须禁用 ssl 检查.我已经阅读了许多有关 stackoverflow 的解决方案,但都没有帮助.问题是我无法在服务器上进行任何更改.所以我想知道如何禁用 ssl 检查,或者是否有任何其他 api,如 fetch api 或 Retrofit 用于反应原生.?
我的fetch 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

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

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) => {
  // ...
})

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

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