Angularjs Can';t通过Angular1s$http发送传入的Slack hook消息

Angularjs Can';t通过Angular1s$http发送传入的Slack hook消息,angularjs,xmlhttprequest,webhooks,slack,Angularjs,Xmlhttprequest,Webhooks,Slack,这是我的http请求 $http({ method: 'post', dataType: 'json', data: { 'username': 'HiBye', 'icon_emoji': ':ghost:', 'channel': '#hcbcrepowatch', 'text': 'hello world!' }, url: 'https://hooks.slack.com/services/xxxx/xxxx', header: {

这是我的http请求

$http({
  method: 'post',
  dataType: 'json',
  data: {
    'username': 'HiBye',
    'icon_emoji': ':ghost:',
    'channel': '#hcbcrepowatch',
    'text': 'hello world!'
  },
  url: 'https://hooks.slack.com/services/xxxx/xxxx',
  header: {'Content-Type': 'application/json'}
}).then(function(result){ 
  console.log('success');
  console.log(result);
}, function(error){
  console.log(error);
});
我得到以下错误:

XMLHttpRequest cannot load ... Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
其中返回的错误对象包含以下数据:null,状态:-1,状态文本:“”

当我将data:to body:I更改为响应对象时,我得到一个数据为:“无效的负载”,状态为500,状态为text:“服务器错误”


我不知道该从这里走到哪里,我所有的谷歌搜索都没有真正起到作用。

我什么都不知道,我之所以在这里发帖,是因为我和你在同一条船上,遇到了一个修复程序,我相信这正是你的问题所在

经过大量搜索,我最终将JSON数据包装到
JSON.stringify()

例如,“我的数据”:如下所示:

data: JSON.stringify({"text": "Dude"})
你所有的东西都和我的一样


也许这能帮你解决问题?希望如此。祝你好运。

此外,我昨天还了解到,JSON数据需要加引号,而不是撇号。这对我来说没什么意义,但我同意了。是的,就是这样。。。在这篇文章发表后不久,我就用CURL在服务器端完成了所有的工作,但是我回去做了一个快速测试,您的修复程序成功了。想想看,当我使用JSON.stringify时,我忘记了我的内部{}或一些愚蠢的东西。此外,可能是“”而不是“”完成了此操作。。。。