1

Currently, my app is not working, and it prints out an error message "network request failed".

The URL is correct - the URL is woking properly in Chrome, however, it only not working on the android.

I am assuming that it is basically because I am using private certificate for https.

Below is my code, please let me know if you find an answer.

fetch(url) .then(res => res.json()) .then( (result) => { const companyName = result['name']; const companyId = 'ID ' + result['id'];

      this.setState({
        isLoaded: true,
        siteData: result,
        companyName: companyName,
        companyID: companyId
      });
    }
  )
  .catch((error) => {
    console.log(error);
    this.setState({
      isLoaded: false,
      error
    });
  });

2 Answers 2

1

The answer is ok, but in my case i had to change the manifest too:

<application
...
android:usesCleartextTraffic="true"
...>
Sign up to request clarification or add additional context in comments.

Comments

0

Ahh, it works perfectly fine with http - the actual problem was the self-certificate https.

Apparently, the data fetching component in Android blocks the self certificate https due to the security problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.