Network requests not working on react native

Viewed 56

I need you help. For several days I have spent hours and hours trying, and looking for a solution but nothing.

I have to make a network request to use the TMDB API. So I do this (for example):

    const url = 'https://api.themoviedb.org/3/movie/550?api_key=XXXXXXXXX'
console.log(url)

return fetch(url,{
    method: 'GET',
    headers: {
        Accept: '*/*',
        'Content-Type': 'application/json',
        'accept-encoding': 'gzip, deflate, br'
    }
})
    .then((response) => {
        console.log(response)
        response.json()
    })
    .catch((error) => {
        console.error(error)
    })
    .finally(() => {
        console.log('fini')
    })

But I never have response. I have try with fetch and Axios, but it's always the same: no response, no error, noting. The request works when I test it in my browser, it works on Postman and cURL, but not in my app.

For information I'm using an Android emulator, and I added android:usesCleartextTraffic="true" in the AndroidManifest file.

This is not my first React Native app and I never had this problem before.

Thank you in advance for taking the time to read me !

PS: I add a capture of the test made on jsfiddle.net and its equivalent on the android emulator.

Test on jsfiddle.net

--

Test on Android emulator

1 Answers

I don't really know why, but my problem is solved.

I installed a debugger in order to analyze the network requests and see what could be the problem, and once installed, without changing the code, the problem was no longer present...

I followed the procedure of this post: https://stackoverflow.com/a/55450655/13052339

Related