如何从 react native 调用在 localhost 上运行的 api。我正在使用 expo cli 并使用 expo app 在真实设备上运行该应用程序。我尝试 fetch("https://localhost:3000") 但这没有工作请帮忙!!
网络错误 在 node_modules\axios\lib\core\createError.js:16:14 in createError 在 node_modules\axios\lib\adapters\xhr.js:84:24 中的 handleError 在 node_modules\event-target-shim\dist\event-target-shim.js:818:20 在 EventTarget.prototype.dispatchEvent 在 node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 在 setReadyState 在 __didCompleteResponse 中的 node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 在 node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 在发射 在 __callFunction 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 在 __guard$argument_0 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 在 __guard 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 在 callFunctionReturnFlushedQueue at [native code]:null in callFunctionReturnFlushedQueue
答案 0 :(得分:0)
尝试将 https 更改为 http 确保您的服务器在端口 3000 上运行。
fetch("http://localhost:3000").then((data)=>{
console.log(data);
});