I am using rest services to get the response for my react-native android app. Whenever I am using the localhost(i tried with 127.0.0.1) with port 8080 but fetch is giving me [TypeError: Network request failed]. Fetch request is working fine without localhost. Rest service is working fine when used with Postman.
I am running my code using expo. And for backend dependency using Maven.
I tried with both physical device and emulator both failed, checked with port 9090. I tried to change the server address in the application.properties file after which spring-boot backend stopped which is due to server address configuration problem. (Error: APPLICATION FAILED TO START
Description:
The Tomcat connector configured to listen on port 9090 failed to start. The port may already be in use or the connector may be misconfigured.
Action:
Verify the connector's configuration, identify and stop any process that's listening on port 9090, or configure this application to listen on another port.)
insertPost() {
return fetch('http://127.0.0.1:9090/getPost/PO397ba3306cc211e98f8249277cd661ec')
.then(res => res.json())
.then(json => {
console.log(json)
})
.catch(error => console.error(error));
}
console.log(json) should print the object returned from fetch.
server.port=some other port