这里只是处理语法错误。尝试在HTTPotion
请求的正文中发送有效负载。试图以json的形式发送数据,但不确定我哪里出错了。
HTTPotion.post "https://hooks.slack.com/services/a00000/b0000/XXXXXXX", [body: "{'channel': '#general', 'username': 'thedanotto', 'text': 'Pokemon are scary!', 'icon_emoji': ':ghost:'}", ["Content-Type": "application/json"]]
=> ** (SyntaxError) iex:1: syntax error before: '['
有什么想法吗?
答案 0 :(得分:3)
您在标题列表前缺少headers:
。这应该有效:
HTTPotion.post "https://hooks.slack.com/services/a00000/b0000/XXXXXXX", [body: "{'channel': '#general', 'username': 'thedanotto', 'text': 'Pokemon are scary!', 'icon_emoji': ':ghost:'}", headers: ["Content-Type": "application/json"]]
答案 1 :(得分:2)
您错过了headers
密钥
应该是这样的:
HTTPotion.post "https://hooks.slack.com/services/a00000/b0000/XXXXXXX", [body: "{'channel': '#general', 'username': 'thedanotto', 'text': 'Pokemon are scary!', 'icon_emoji': ':ghost:'}", headers: ["Content-Type": "application/json"]]