问题
Just dealing with a syntax error here. Trying to send the payload in the body of the HTTPotion
request. Trying to send the data as json, but not really sure where I'm going wrong.
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: '['
Any ideas?
回答1:
You're missing headers:
before the headers list. This should work:
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"]]
回答2:
You're missing headers
key
It should be like this:
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"]]
来源:https://stackoverflow.com/questions/38602879/post-to-slack-api-with-httpotion-elixir