reactjs - Laravel React 419 对 POST 请求,而 XCSRF 在标头中
问题描述
如上所述,我每次尝试发布到控制器时都会收到 419。
const handleSubmit = useCallback((_event) => {
window.axios.defaults.headers.common = {
'X-CSRF-TOKEN' : document.querySelector('meta[name="csrf-token"]').getAttribute('content')
};
console.log(document.querySelector('meta[name="csrf-token"]').getAttribute('content'));
axios.post('/bol/accounts/create', {
bol_public_key: '12345454',
bol_private_key: '123454'
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
}, []);
令牌在请求标头中,所以应该没问题吗?
:authority: *.ngrok.io
:method: POST
:path: /accounts/create
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: nl-NL,nl;q=0.9
cache-control: no-cache
content-length: 86
content-type: application/json;charset=UTF-8
origin: https://8be933f3b3a6.ngrok.io
pragma: no-cache
referer: https://*.ngrok.io/?hmac=564b7bb3c74e59e7a578e50f3bbfb318dfc3d7dea58820d9d66b46ade87b6659&locale=en-NL&new_design_language=true&session=d39033c75fb0a751a23596feae7cb86f704114e33b2bd1c676ddd1bea05ab759&shop=*.myshopify.com×tamp=1607901296
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
x-csrf-token: tUQk4qMxSNIvTx07oePArv94CEk2LedNmadu2Ozs
解决方案
推荐阅读
- python - 从脚本以编程方式调用 Jupyter Notebook 魔术命令
- python - 填充 Django SQL 数据库
- amazon-web-services - 如何从命令行下载/拉取 lambda 代码到本地机器?
- arrays - 如何遍历c中函数传递的结构数组?
- node.js - MongoDB 发现 $in 排序问题
- corda - 我们如何在 CordApp 的 Contract-States 库中访问 NetworkMapCache
- github - 如何以编程方式阻止 GitHub PR 合并
- grafana - 使用 kubeflow 的 Grafana
- unity3d - Unity 上的项目路径无效
- c# - ADODB.Command,查找满足条件的行