【发布时间】:2020-09-21 17:45:15
【问题描述】:
网络请求失败
我已尝试允许端口连接 通过 sudo ufw 允许任何端口命令,但它没有帮助
fetch('http://192.XXXXXX//form/user_registration.php',
{
method: 'POST',
headers:
{
'Accept': 'application/json',
'Content-Type': 'application/json',
},
网络请求失败
堆栈跟踪:
node_modules/react-native/Libraries/vendor/core/whatwg-fetch.js:504:29 in onerror
node_modules/event-target-shim/lib/event-target.js:172:43 in dispatchEvent
node_modules/react-native/Libraries/Network/XMLHttpRequest.js:580:29 in setReadyState
node_modules/react-native/Libraries/Network/XMLHttpRequest.js:394:25 in __didCompleteResponse
node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12 in emit
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:366:47 in __callFunction
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:106:26 in <unknown>
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:314:10 in __guard
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:105:17 in callFunctionReturnFlushedQueue
...
【问题讨论】:
-
尝试将 192.168.1.18:8082//form/user_registration.php 更改为 192.168.1.18:8082/form/user_registration.php ..您在域后使用 2 个斜杠
-
不工作我认为问题不在于我的设备无法访问本地服务器
-
API 地址不使用 localhost:port,而是使用服务器的 IP 地址。
-
这是 nginx 的 ip 地址,我也更改了端口并允许 ufw 开放对该端口的访问
-
你试过在浏览器中打开网址吗?
标签: react-native