简体   繁体   中英

Connecting react native and node js

how do call an api running on localhost from react native.I am using expo cli and running the app on real device using expo app.I tried fetch("https://localhost:3000") but that doesn't work pls help!!

Network Error at node_modules\axios\lib\core\createError.js:16:14 in createError at node_modules\axios\lib\adapters\xhr.js:84:24 in handleError at node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 in setReadyState at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 in __didCompleteResponse at node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0 at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue at [native code]:null in callFunctionReturnFlushedQueue

try to change https to http make sure your server is running on port 3000.

fetch("http://localhost:3000").then((data)=>{
  console.log(data);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM