问题描述
我正在尝试使用 Slack的chat.postMessage API调用发送消息.我在HTTP GET中对测试消息进行编码没有问题,但是我试图在HTTP POST请求中使用JSON实现相同的结果.
I'm trying to send a message using Slack's chat.postMessage API call. I have no problems encoding my test messages within HTTP GET, but I'm trying to achieve the same result with JSON in a HTTP POST request.
我一直在使用curl
和邮递员进行测试,但是Slack似乎并没有承认我的请求正文全部.
I've been testing with both curl
and Postman, but Slack doesn't seem to be acknowledging my request body at all.
{
"ok": false,
"error": "not_authed"
}
在curl
中,我的请求是这样编码的:
In curl
, my request is encoded like this:
curl -H "Content-type: application/json" -X POST -d '{"token":"my-token-here","channel":"#channel-name-or-id","text":"Text here.","username":"otherusername"}'
在邮递员中,这是原始内容:
In Postman, this is the raw body:
{
"token":"my-token-here",
"channel":"#channel-name-or-id",
"text":"Text here.",
"username":"otherusername"
}
我以前没有做过这样的事情,所以我不确定是否遗漏了一些东西.谢谢!
I haven't done anything like this before, so I'm not sure if I'm missing something out. Thanks!
推荐答案
我来晚了一些,但我希望这可以帮助像我一样偶然发现此问题的其他人.我刚刚与Slack保持联系,这就是他们告诉我的:
I'm a bit late, but I hope this can help other people who stumble into this issue like me. I've just been in touch with Slack, and this is what they told me:
我们计划在将来支持JSON数据,以确保将来的一致性.
We plan to support JSON data in the future for consistency in the future.
因此,您的cURL行应如下所示:
So, your cURL line should look like:
curl -X POST -d 'token=my-token-here&channel=#channel-name-or-id&text=Text here.&username=otherusername'`
我希望这会有所帮助! :)
I hope this helps! :)
这篇关于在HTTP POST请求中将JSON发送到Slack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!