react-native - 使用 react-native 获取网络请求失败
问题描述
我是一个 fetch 的初学者,并试图从 JSON-server 获取一些数据到我的 react native 应用程序,但它总是给我同样的错误......“网络请求失败”我试图使用 Ip 而不是 localhost,如“ http:/ /192.168.xx:3000 " 但没有任何改变,我的博览会是 192.168.xx:19000。我忘了做什么?为什么这个错误总是发生?
export const fetchDishes = () => (dispatch) => {
dispatch(dishesLoading());
return fetch("http://192.168.1.5:3000/dishes")
.then(
(response) => {
if (response.ok) {
return response;
} else {
var error = new Error(
"Error " + response.status + ": " + response.statusText
);
error.respone = response;
throw error;
}
},
(error) => {
var errmss = new Error(error.message);
throw errmss;
}
)
.then((respone) => respone.json())
.then((dishes) => dispatch(addDishes(dishes)))
.catch((error) => dispatch(dishesFailed(error.message)));
};
解决方案
推荐阅读
- apache-kafka-connect - ksql表中的重复键
- python - 在尝试训练之前查看我的神经网络的架构
- python - tensorflow.python.framework.errors_impl.UnimplementedError:文件系统方案'gs'未实现
- jquery - Datatable.js:点击数据表中的编辑按钮时页面回发
- python - 在 Django 中,表单提交工作但无法解析用户输入
- postgresql - How do i SELECT multiple Values with postgreSQL INTO multiple variables Depending on a CASE?
- node.js - Node.Js - Return 1 if no matching document is found in MongoDB
- python - 没有管道的工作进程最有效的方法
- asp.net-mvc - 使用页面处理程序部分页面 .net 核心发布表单
- sql - SQL Aggregation with rolling window