JavaScript将JSON POST请求发送到Mattermost传入webhook

时间:2018-06-10 04:07:21

标签: javascript ajax http-post mattermost

我是Javascript的新手,目前正在编写一个脚本,它将一些字符串作为JSON发送到Mattermost传入钩子(Mattermost只接受JSON数据)。我已经用curl对它进行了测试,它没有任何问题,命令如下:

curl -i -X POST -H 'Content-Type: application/json' -d '{"text": "Hello, this is some text\nThis is more text. :tada:"}'http://mattermost.test.nz/hooks/xxxxxxxxxxxxxxxxxxx

这是我写的脚本,它不是出于某种原因将数据发送到端点,我试图自己解决这个问题,但它只是不起作用。请任何人帮忙..

var xmlhttp = new XMLHttpRequest();
var url = "http://mattermost.test.nz/hooks/xxxxxxxxxxxxxxxxxxx";
var data = {"test"};
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/json; charset=UTF-8");
xmlhttp.send(JSON.stringify(data));

0 个答案:

没有答案