Reputation: 21
I got a big situation here. I'm using Mobx and axios, i'm trying to post a request with axios on localhost, who calls my api made with Symfony.
Here's the code :
@action async inscriptionAxios() {
const query = {
"nom": "Johan11",
"prenom": "Louap11",
"email": "[email protected]",
"dateNaissance": "1996-12-11",
"login": "Leiko9849",
"password": "mdpLeiko118198"
};
const header = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
console.log('query', query, header)
await axios
.post('http://localhost:8000/register', query, header)
.then(response => {
console.log('response _inscriptionAxios', response)
// extendObservable(this._reservation, response.data)
this._inscription = Object.assign({}, response.data)
})
.catch ((err) => {
console.log('Erreur : ' + err)
})
}
But I got this error response : "Error: Network Error" And error.response "undifined"
I tried to change "localhost" to my ip adress and it did not work. I tried to change "localhost" to 127.0.0.1 and it did not work to.
Can I make it work ??
Thanks boys
Upvotes: 1
Views: 2279
Reputation: 103
First, try with these ip addresses 10.0.2.2 or 10.0.3.2 if you are using android emulator(AVD) or genymotion emulator.
If the first approach is failed, try this command below at your terminal if your local server itself is working fine with postman.
adb reverse tcp:8000 tcp:8000
I had a similar issue before that happened with RN Android app.
I have had setup golang server locally but could not sent a request from my android test device. What I have found is something that related to port of local RN package server. Maybe you also need to forward your port of the localhost.
Upvotes: 1