获取请求失败,带有axios get的状态代码403 [英] Getting Request failed with status code 403 with axios get
本文介绍了获取请求失败,带有axios get的状态代码403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经这样设置了我的axios:
I have setup my axios like this:
const agent = new https.Agent({
rejectUnauthorized: false
});
并发送这样的get呼叫:
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:
请求失败,状态码为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': '*'
}
});
推荐答案
我猜想这与在使用axios时未发送CSRF cookie有关.您可以考虑两种方法
I guess it has something to do with CSRF cookie not being sent when you are using axios. You can consider two approach
-
要么使用 axios-cookiejar-support 添加发出请求
或使用提供内置功能的 got .
OR use got which provides this inbuilt.
因此您的代码将很简单
const got = require("got");
(async () => {
console.log(await got.get("https://www.skechers.com/en-us/"));
})();
这篇关于获取请求失败,带有axios get的状态代码403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文