Ale*_*ros 7 https reactjs react-native axios expo
嗨,我目前正在使用 Expo 在 Android 上使用 React Native。我正在尝试向具有有效 ssl 证书的服务器发送请求,但由于某种原因 axios 将其视为无效,因此 axios 不允许我向服务器的 api 发送请求。
这是我得到的错误:
Error: Network Error
所以想知道有没有什么办法可以让axios忽略ssl的问题,可以正常发送请求
这是我的代码:
try {
const headers = {
'Accept-Language': 'es-ES,es;q=0.8',
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
};
axios.get("https://URLtoMySERVER", {}, headers)
.then(response => {
console.log(response)
const posts = response.data;
console.log(posts)}
).catch(function(error) {
console.log("error", error);
});
} catch (error) {
console.log('err', error);
}
Run Code Online (Sandbox Code Playgroud)
我想澄清的几点:
1- 我不能使用 RNFetchBlob,因为我使用的是 Expo,而 RNFetchBlob 有一些本机库。
2- 我不能将 httpsAgent 与 axios 一起使用,因为显然 https 库不适用于 expo,或者至少它对我不起作用。
3- fetch 也不起作用
有没有其他替代 axios 或 fetch 可以在与 expo 本地反应的情况下工作的,并且您可以忽略 https 的问题?