我正在使用XAMPP for API
我在控制台中遇到此错误:
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';
但是我在另一个网站上尝试过,但是我成功了
答案 0 :(得分:0)
知道了!我将“ localhost”更改为我的IPV4并成功工作