我正在使用expo v33运行一个react原生程序。我需要使用fetch从web服务器获取json格式的数据。
当调用
fetch('https://elpuente.io', {
method: "GET",
})
.then((response) => console.log(response))
.catch((error) => {
console.error(error);
});
我得到这样的警告:
Network request failed
Stack trace:
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
...
使用localhost时,一切正常。我也尝试过使用ip地址获取,但得到了同样的警告。
谢谢。
发布于 2019-09-17 18:25:30
可以在服务器上禁用重定向到https并使用http
https://stackoverflow.com/questions/57944146
复制相似问题