2016-07-27 2 views
2

Just Umgang mit einem Syntaxfehler hier. Versucht, die Nutzlast im Körper der Anfrage zu senden. Versucht, die Daten als JSON zu senden, aber nicht wirklich sicher, wo ich falsch liege.Post zu locker api mit httpotion Elixier

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: '['

Irgendwelche Ideen?

Antwort

3

Sie fehlen headers: vor der Header-Liste. Dies sollte funktionieren:

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

Sie verpassen headers Schlüssel

es so sein sollte:

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"]]