I´ve came across the following error. At the moment I developing an Android App with React Native therefore I´m planning to use fetch for doing a post request for me.
fetch("https://XXreachable-domainXX.de/api/test", {
method: "post",
body: JSON.stringify({
param: 'param',
param1: 'param',
})
}
)
.then((response) = > response.json()
)
.
then((responseData) = > {
ToastAndroid.show(
"Response Body -> " + JSON.stringify(responseData.message), ToastAndroid.SHORT
)
})
.
catch((error) = > {
console.warn(error);
})
;
The app now throws an error:
TypeError: Network request failed
When I change the code to a GET-Request it´s working fine, in the browser with a window.alert() as a return it´s cool and also the chrome extension Postman returns data correctly.
Developing with Windows OS/PHP built-in server/react-native Android on device:
ipconfig
), e.g. 172.16.0.10fetch
use this URL and proper port (fetch('http://172.16.0.10:8000/api/foo)
)php -S 172.16.0.10:8000 ...
That fixed the connection problem between Android phone and the local server for me.