本文介绍了axios删除方法给出了403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从我的node-js应用程序中调用delete方法.
I am calling delete method from my node-js application.
下面是我的示例代码片段:
Below is my sample code snippet:
const instance = axios.create();
instance.interceptors.request.use((config) => {
config.baseURL = 'https://test-dev.com/api/portfolio'
config.headers = { 'Authorization' : 'Bearer ' + <TOKEN>}
return config;
});
instance.delete('/admin?users=<VALUE>').then(function(response) {
console.log("Deleted: "+<VALUE>);
}).catch(function (error) {
console.log("Deletion failed with error:" + error);
});
响应(来自Spring Security APP):
Response (Coming from spring security APP):
我认为这已经由axios处理.
I thought this is already handled by axios.
在调用delete方法时如何在标头中传递此值?
How can i pass this value in headers while calling delete method?
有帮助吗?
推荐答案
您可以:
1-使用withCredentials属性:
withCredentials: true
如此:
axios.delete({
url: 'https://test-dev.com/api/portfolio/admin?users=' + <VALUE>,
headers: { 'Authorization' : 'Bearer ' + <TOKEN>},
withCredentials: true
}).then(function(response) {
console.log("Deleted: "+<VALUE>);
}).catch(function (error) {
console.log("Deletion failed with error:" + error);
});
2-设置CSRF标头
要么:
headers: {'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-TOKEN' : document.querySelector('meta[name="csrf-token"]').getAttribute('content')}
或
headers: {'X-Requested-With': 'XMLHttpRequest',
'X-CSRFToken': 'your token here'}
或者只是:
headers: {'X-Requested-With': 'XMLHttpRequest'}
3-禁用风险自负,
看看这篇文章
这篇关于axios删除方法给出了403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!