当我发出api请求时,我在react-native ios应用程序中收到以下错误。
我使用axios发出api请求。
Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:87)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:546)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:381)
at XMLHttpRequest.js:485
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:306)
at MessageQueue.js:108
at MessageQueue.__guard (MessageQueue.js:269)
这是我的代码:
axios.get('http://myapi')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
答案 0 :(得分:4)
你需要这样做iOS App Transport Security and loading HTTP resources
因为默认情况下iOS不允许http连接,您需要通过在info.plist中设置App Transport Security Setings来启用它。