[英]Data not passing in axios post request
I'm using axios
to call a post request as follows:我正在使用axios
调用 post 请求,如下所示:
axios.post(this.api+'&action='+this.action+'&wftkn='+this.wftkn, {name: 'Abcd'}).
then((res)=>{
});
When I check the network tab, I don't see the data being passed in the Request header.当我检查网络选项卡时,我看不到请求标头中传递的数据。 What would be the issue in this case?在这种情况下会出现什么问题?
Please try this: 请尝试以下方法:
axios.post(this.api, { name: 'Abcd' }, {
params: {
action: this.action,
wftkn: this.wftkn,
}
}).then((res)=>{});
It's a protection from the browser, you're requesting a resource on a different domain, so you need to set a response header : 这是浏览器的一种保护,您正在请求其他域上的资源,因此您需要设置一个响应标头:
Access-Control-Allow-Origin: http://localhost:8000
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
Axios will work on most any web server when you use specific arguments.当您使用特定参数时,Axios 将适用于大多数 Web 服务器。 Often time this issue occurs due to GET
or POST
conflict or faulty / missing headers.由于GET
或POST
冲突或错误/缺少标头,通常会发生此问题。
axios.request({
method: 'POST',
url: `https://stackoverflow.com/end-point`,
headers: {
'Authorization': 'token'
},
data: {
title: 'abc'
},
})```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.