I'm using React native for developing an android application. With this fetch request I'm getting the error TypeError: network request failed
:
fetch('https://pixabay.com/api/?key=MY_KEY&q='+ this.props.jsondata.city.name +'&lang=en&image_type=photo&orientation=horizontal&category=travel&safesearch=true') .then(response => { console.dir(response); if (!response.ok) { throw Error(data.statusText); } return response.json(); }) .then(json => { console.log(json.hits[0].largeImageURL) this.setState(() => { return {backImage: json.hits[0].largeImageURL}; }); }) .catch(err => { console.log('Unable to search image! '+ err); });
I've already searched online but this problem appears only with localhost addresses or http, that is not my case. The request is inside the componentDidMount()
function. I've made a similar request (with the same structure) in an another place of the application but there is no error there. I'm using a real android device to testing the app with the react-native app compiled in android native code.