node.js - 在具有 Node.js 后端的 React Native 应用程序中使用 Axios 获取请求的网络错误
问题描述
我已经尝试了 Stack Overflow 的一些解决方案,但仍然无法解决这个问题。需要其他解决方案。
componentDidMount(){
this.getCar()
}
async getCar() {
try {
const response = await axios.get('http://127.0.0.1:8000/topratedcars');
console.log(response);
} catch (error) {
console.error(error);
}
}
解决方案
嗨,我认为您可以尝试使用 ngrok 之类的服务将您的本地主机暴露在互联网上,该服务将为您生成一个 url,然后尝试使用该 url 从您的代码发送请求。只需下载并按照此处的说明进行操作:https ://ngrok.com/docs
推荐阅读
- java - Spring MVC + Log4j2 在未识别的无类路径位置中定义 log4j2.properties 文件
- angular - 在 Angular Reactive Forms 中使用嵌套的 FormArray 将对象转换为 FormGroup
- php - laravel scout 可搜索特征
- spring - Spring Boot JPA Repository:在 Spring Boot 中从普通 Java 类访问 JPA 存储库函数
- python - uWSGI + Django:ImportError:没有名为“wsgi”的模块
- winapi - 在启用 GDI 缩放的 Windows 10 上保存位图
- php - 使用 PHP 修改 WordPress 中的类别模板
- angular - Angular 6 lib 提供程序错误
- bootstrap-4 - 如何限制 Bootstrap datetimepicker 未来的日期?
- machine-learning - 使用 Fortran 导入 MNIST 数据集