Reputation: 61
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
});
});
Upvotes: 1
Views: 660
Reputation: 104
The answer is ok, but in my case i had to change the manifest too:
<application
...
android:usesCleartextTraffic="true"
...>
Upvotes: 1
Reputation: 61
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.
Upvotes: 0