Sunil tc
Sunil tc

Reputation: 2602

Error: Network Error in react-native

I'm getting the following error in my react-native ios application when I make api request.

I'm using axios for making api request.

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)

This is my code:

axios.get('http://myapi')
    .then(function (response) {
    console.log(response);
})
.catch(function (error) {
      console.log(error);
});

Upvotes: 1

Views: 2549

Answers (1)

Mohamed Khalil
Mohamed Khalil

Reputation: 3126

you need to do this iOS App Transport Security and loading HTTP resources

because iOS not allow http connection by default you need to enable it by setting App Transport Security Setings in info.plist

App transport security

Upvotes: 4

Related Questions