Reputation: 4625
I'm making a POST request to my own server and my server doesn't even receive any request (no request was shown in server terminal).
I can use an internet on browser inside of the simulator. But it's giving me the error below.
Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:87)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:546)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:381)
at XMLHttpRequest.js:485
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:260)
at MessageQueue.js:101
at MessageQueue.__guard (MessageQueue.js:228)
And below is my POST request using axois
export const doAuthLogin = ({ username, password }) => async dispatch => {
axios.post(`${ROOT_URL}/rest-auth/login/`, {
username,
password
}).then(response => {
console.log(response);
// Save Token post is Already await.
AsyncStorage.setItem('auth_token', response.token);
dispatch({ type: AUTH_LOGIN_SUCCESS, payload: response.token });
})
.catch(response => {
console.log(response);
dispatch({ type: AUTH_LOGIN_FAIL, payload: response.non_field_errors });
});
};
What is Network Error? And how can I fix it?
Thank you so much!!
Upvotes: 1
Views: 3599
Reputation: 2220
If you put your API in localhost you can do the following steps.
Check your laptop IP by typing ifconfig
(for ubuntu and mac) or ipconfig
(for windows). For example you got 192.168.40.6
Run your django for examplepython manage.py runserver 192.168.40.6:8000
Specifiy your axios url. For example
axios.post(http://192.168.40.6:8000/rest-auth/login/
, {...})
Make sure your phone connect to the same wifi with your laptop, and you can try the connection in your phone browser by go to http://192.168.40.6:8000
Upvotes: 1