I am geting the Network request failed error when i am using the axios in my reactr native ios and android app, Its working fine when i am testing with postman.
const getCourseLesson = async () => {
await axios({
method: 'GET',
url: `${API_URL}getCourseLesson`,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
let lessonDataList = res.data.data;
setLessonList(lessonDataList);
})
.catch(res => {
console.log('lesson error ', res);
});
};
2
Answers
I tried your code with a sample url and its working fine .. are you sure your Api url is correct?
Could you share the full result of => url:
${API_URL}getCourseLesson
Make sure your ${API_URL} ends with a ‘/’, something like:
http://localhost:8080/getCourseLesson
Also your Headers, make sure you add quotes to your ACCEPT:
headers:
{
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’,
},