简体   繁体   中英

react native - Android 4.4 cannot fetch data from PHP server

I got a weird issue. My application is able to fetch everything from server when it is installed on Android version 5.0. However, the app cannot fetch anything from server when it is installed on Android version 4.4.

My server is using PHP code. My application is using React native code.

Here is the network code in my application which copied from React native network :

function getMoviesFromApiAsync() {
    return fetch('https://facebook.github.io/react-native/movies.json')
        .then((response) => response.json())
        .then((responseJson) => {
            return responseJson.movies;
        })
        .catch((error) => {
            console.error(error);
        });
}

When I replace the URL by my own one, the fetch function throws an error Network request fail even my real android device has strong network connection.

Here is my testing environment:

  • React native version 0.57
  • Android real device version 4.4
  • Real URL, not locahost

If there is any solution to make the api request work for Android version 4.4, please let me know.

Thank you in advance!

Thank you all, I found these links:

Android 4.x cannot fetch api

Why Android 4.x to fetch API - missing TLS

Solution for missing TLS

Actually, because Android 4.x has TLS 1.1 and 1.2 inside but not enabled, we cannot make a request to a server which has TLS 1.1 or 1.2. We need to enable them first in order to do that

Thank you again for all the comments. I really appreciate it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM