I am trying to make a http post request with HTTPoison
.
I want to pass json data with header, which contains "Authorization": Bearer #{token}
.
In order to achieve that, I have tried,
headers = [{"Authorization": "Bearer #{token}"}, {"Content-Type", "application/json"}]
body =
%{
id: id,
name: name,
...
}
HTTPoison.post(url, body, headers)
But it triggers a syntax error that syntax error before: "Authorization"
. And I have been searching for right syntax for headers but still no luck..
What is correct syntax for headers
?
Thanks in advance..
I believe, the correct syntax should be as follows:
or, if you prefer the "tuple" way of defining keyword, this would be the equivalent:
Hope it helps!