我尝试使用原始JSON向Slack API发出POST请求,但我不断收到下面的错误
CORS策略已阻止从来源“ https://hooks.slack.com/services/conuation/of/the/url”访问“ http://localhost:8080”处的XMLHttpRequest:access-Control-Allow-不允许请求标头字段access-control-allow-origin飞行前响应中出现标题。
下面是代码
const params = {
"attachments":[
{
"fallback":"New Project Lead:<" + this.our_website + "|Click here to view>","pretext":"New Project Lead:<" + this.our_website + "|Click here to view>","color":"#D00000","fields":[
{
"title":"Company","value":this.user_company,"short":false
},{
"title":"Country","value":getName(this.user_country),"short":false
}
]
}
]
};
this.axios.post('https://hooks.slack.com/services/continuation/of/url',params,{
headers: {
'content-type': 'application/json','access-control-allow-origin' : '*',},}).then((response)=>{
loader.hide();
let msg = "Sent Successfully";
this.displayAlert("Done",msg,"success");
setTimeout(() => { // redirect to home after 2s
document.location = '/';
},2000);
}).catch((error) =>{
alert(error);
});
}).catch((error) => {
loader.hide();
let msg = "Error : " + error;
this.displayAlert("Error","error");
});
我正在使用VueJS和Axios HTTP库进行通话。每当我用POSTMAN测试时,它都可以正常工作。