【问题标题】:HTTPS calls are not working in React NativeHTTPS 调用在 React Native 中不起作用
【发布时间】: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


【解决方案1】:

您是否在 androidManifest 中为您的应用设置了适当的权限? 顺便说一句,你为什么不试试“./gradlew bundleRelease”?

【讨论】:

  • 如何在 AndroidManifest 中为https 设置权限?我检查了./gradlew bundleRelease 同样的问题。 :(
猜你喜欢
  • 2021-11-23
  • 1970-01-01
  • 2017-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多