skip to Main Content

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


  1. I tried your code with a sample url and its working fine .. are you sure your Api url is correct?

        const getCourseLesson = async () => {
            await axios({
                method: 'GET',
                url: `https://random-data-api.com/api/v2/users?size=2`,
                headers: {
                    Accept: 'application/json',
                    'Content-Type': 'application/json',
                },
            })
                .then(res => {
                    console.log('res.data', res.data)
                })
                .catch(res => {
                    console.log('lesson error ', res);
                });
        };
    Login or Signup to reply.
  2. 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’,
    },

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search