gpt4 book ai didi

ssl - 如何在 react native XMLHttpRequest API 或 Fetch Api 中禁用 ssl 检查?

转载 作者:太空宇宙 更新时间:2023-11-03 12:51:07 30 4
gpt4 key购买 nike

在本地测试服务器 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);
});

最佳答案

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

rn-fetch-blob

包。要连接具有自签名证书的服务器,您需要在配置中显式添加 trusty

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

关于ssl - 如何在 react native XMLHttpRequest API 或 Fetch Api 中禁用 ssl 检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51130878/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com