php - 网络错误 Axios 试图从 localhost 获取数据
问题描述
我正在为 API 使用 XAMPP
我在控制台中有这个错误:
Network Error
- node_modules\axios\lib\core\createError.js:15:17 in createError
- node_modules\axios\lib\adapters\xhr.js:80:22 in handleError
- node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:574:29 in setReadyState
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:388:25 in __didCompleteResponse
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue
使用简单的代码:
const apiAsyncTest = async () => {
try {
const response = await axios.get('https://127.0.0.1/api/api.php');
console.log(response);
} catch (error) {
console.log(error);
}
}
apiAsyncTest();
已经检查了android模拟器的互联网,我将“127.0.0.1”更改为“localhost”https到http,但没有任何效果
我的页面 api 代码也包含简单的代码:
<?php
echo 'test';
但是我在另一个网站上试过,我成功了
解决方案
知道了!我将“localhost”更改为我的 IPV4 并成功运行
推荐阅读
- django - 如何使用 django-taggit 删除将在 Django2.2 上未使用的帖子和删除标签
- swift - 为什么我的按钮显示不正确的字符串?
- c# - ASP.NET 核心。如果请求查询字符串为空,则创建 [FromQuery] 参数实例
- java - 如何将可选映射转换为 Java 中的流映射
- android - 每当用户尝试切换到另一个应用程序时,是否有任何更聪明的方法可以将我的应用程序置于顶部。请检查我在 onPause() 中的代码
- modelica - 如何继续模拟 Dymola 中更改参数的运动?
- python - 在 pandas 框架中读取无头的 Rdata
- android - 使用测试模式后Gradle构建失败?
- c++ - C++中的指针是按值传递的吗?
- python - ValueError:无法在空距离矩阵上确定观察次数