Angularjs 带有角度$http POST的松弛Webhook
我试图学习一些基本的SlackAPI知识,并开始为我正在构建的应用程序构建一个webhook 我有以下代码:Angularjs 带有角度$http POST的松弛Webhook,angularjs,post,webhooks,slack,Angularjs,Post,Webhooks,Slack,我试图学习一些基本的SlackAPI知识,并开始为我正在构建的应用程序构建一个webhook 我有以下代码: $scope.postToSlack = function(){ $http({ url: 'https://hooks.slack.com/services/xxx/xxxx/xxxxx', method: "POST", payload:{"text": "This is a line of text in a channel.
$scope.postToSlack = function(){
$http({
url: 'https://hooks.slack.com/services/xxx/xxxx/xxxxx',
method: "POST",
payload:{"text": "This is a line of text in a channel.\nAnd this is another line of text."}
})
.then(function(response) {
console.log(response)
},
function(response) {
console.log(response)
});
}
但不断收到一个500错误,表示没有收到有效负载
想知道为什么这不起作用吗?尝试使用数据而不是有效负载(假设您在服务器上设置了整个访问控制允许源代码) 仅供参考-您可能希望在服务器端执行此操作。只是一个建议:
也许它不是开放式的,或者你只是随便玩玩,但我想我应该早点提出来。下面的内容对我很有用-
$http({
url: slackWebHookUrl,
method: "POST",
data: 'payload=' + JSON.stringify({"text": message,"channel" : slackChannelname, "username" : slackUsername}),
headers: {"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"}
})
.then(function(response) {
console.log("Slack response :" + JSON.stringify(response));
},
function(error) {
console.log("Slack error :" + JSON.stringify(error));
});
添加
标题:{'Content Type':'application/x-www-form-urlencoded;charset=UTF-8'}
使其在客户端工作
$http({
url: slackWebHookUrl,
method: "POST",
data: 'payload=' + JSON.stringify({"text": message,"channel" : slackChannelname, "username" : slackUsername}),
headers: {"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"}
})
.then(function(response) {
console.log("Slack response :" + JSON.stringify(response));
},
function(error) {
console.log("Slack error :" + JSON.stringify(error));
});