Search code examples
javascriptnode.jsweb-scrapinggetaxios

Getting Request failed with status code 403 with axios get


I have setup my axios like this:

    const agent = new https.Agent({
        rejectUnauthorized: false
    });

and sending a get call like this:

    let data = await axios.get('https://www.skechers.com/en-us/', {
        httpsAgent: agent
     });

but with some urls my request fails with this error:

Request failed with status code 403

what would be the possible reason to cause this error. I have tried setting up headers as follow but still getting the error

    let data = await axios.get(url, {
      httpsAgent: agent,
      headers: {
          'Access-Control-Allow-Origin': '*',
          'Access-Control-Allow-Methods': '*'
      }
    });

Solution

  • I guess it has something to do with CSRF cookie not being sent when you are using axios. You can consider two approach

    so your code will be simply

    const got = require("got");
    
    (async () => {
      console.log(await got.get("https://www.skechers.com/en-us/"));
    })();