Getting Request failed with status code 403 with axios get

你。 提交于 2021-01-25 07:09:05

问题


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': '*'
      }
    });

回答1:


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

  • Either use axios-cookiejar-support to add while making the request

  • OR use got which provides this inbuilt.

so your code will be simply

const got = require("got");

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


来源:https://stackoverflow.com/questions/60636207/getting-request-failed-with-status-code-403-with-axios-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!