【发布时间】:2021-05-22 15:45:14
【问题描述】:
我正在使用 Axios 在 React Native 中开发 API 调用,但在使用 ./gradlew assembleRelease 发布后我无法访问后端。在调试模式下,调用正在发生,但我不明白为什么它没有在 Build Release 中发生。 Node & Express 开发的后端在哪里。
这是我附上的代码:
App.tsx
React.useEffect(() => {
getData().then(d => {
setData(d.data)
})
}, [getData])
Services.ts
const getData = async () => {
axios.defaults.headers.Accept = "application/json";
return axios.get(`https://XX.XXX.XX.XXX/course`)
.then((resultant) => {
console.log(resultant)
return resultant.data;
})
.catch((error) => {
console.error(error);
});
}
export {getData}
【问题讨论】:
-
android:usesCleartextTraffic="true"。在你的清单文件中
标签: typescript react-native api axios