简体   繁体   English

AxiosError:React Native 在向本地后端发出 api 请求时出现网络错误

[英]AxiosError: Network Error in React Native on making api request to local backend

Frontend

await axios.get("http://localhost:8000/admin/api/getcategories",{
            "Content-Type": "application/json",
          }).then(result=>{
            console.log(result);
        }).catch(err=>{
            console.log(err);
        })
Backend

const cors = require('cors'); const cors = require('cors');


app.use(cors());

Tried restarting the application, and with other api tried sending without headers, but nothing worked, also added尝试重新启动应用程序,并与其他 api 一起尝试不带标头发送,但没有任何效果,还添加了

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

for android and NSAllowsArbitraryLoads for IOS对于 android 和 NSAllowsArbitraryLoads 对于 IOS

Try to use ngrok ( https://ngrok.com/ ) to make your local API public.尝试使用 ngrok ( https://ngrok.com/ ) 公开你的本地 API。 It is free for developers对开发者免费

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发出简单的 API 请求时出现 React-Native 服务器错误 - React-Native Server Error When making a simple API request 使用 Axios 在具有 Node.js 后端的 React Native 应用程序中获取请求的网络错误 - Network error using Axios get request in React Native app having Node.js backend React Native:获取请求失败并显示错误 - TypeError:网络请求失败(...) - React Native: fetch request failed with error - TypeError: Network request failed(…) 未处理的 Promise 拒绝:AxiosError:网络错误 - Unhandled Promise Rejection: AxiosError: Network Error 使用React Native和API后端进行身份验证 - Authentication with React Native and API backend React Native:使用get请求的Axios网络错误 - React Native: Axios network error using get request 从反应原生移动项目向本地 api 发送获取请求 - Send get request to local api from react native mobile project 从 Localhost:3000 发出请求说 NETWORK FAIL to React Native Project - Making Request from Localhost:3000 says NETWORK FAIL to React Native Project 向节点后端 api 发出响应发布请求时,某些字段不会发送到数据库 - some fields are not send to the database when making a react post request to a node backend api 网络错误 React(frontend) 和 Nodejs(backend) - Network error React(frontend) and Nodejs(backend)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM