Skip to content

Instantly share code, notes, and snippets.

@thluiz
Created February 1, 2015 21:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thluiz/24494c150640b87d7d7a to your computer and use it in GitHub Desktop.
Save thluiz/24494c150640b87d7d7a to your computer and use it in GitHub Desktop.
HTTPoison post url encoded form
headers = [
{"Content-Type", "application/x-www-form-urlencoded"},
{"Accept", "text/html"}
]
encoded_text = URI.encode_www_form(text)
body = "text=#{encoded_text}"
case HTTPoison.post(url, body, headers) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
body
{:ok, %HTTPoison.Response{status_code: 404}} ->
"Not found :("
{:error, %HTTPoison.Error{reason: reason}} ->
reason
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment