Created
February 1, 2015 21:51
-
-
Save thluiz/24494c150640b87d7d7a to your computer and use it in GitHub Desktop.
HTTPoison post url encoded form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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