Srene
HTTPosion request format
Hi…
I have the following in python:
response = requests.post(url,data=parameters, auth=(api_key, ‘’))
What is the HTTPoison ot HTTPotion equivalent for this.
Thanks.
Most Liked
NobbZ
Please do not assume that anyone does know what a certain snippet in a foreign language does. Please try to explain how the request should look like.
collegeimprovements
HTTPoison is cool but take a look at Tesla also.
Link: GitHub - elixir-tesla/tesla: The flexible HTTP client library for Elixir, with support for middleware and multiple adapters. · GitHub
Documentation: API Reference — tesla v1.20.0
markkauffman2000
HTTPoison POST Example. Auth goes into the trailing options.
post!(url, body, headers \\ [], options \\ [])
iex(7)> {code, response} = HTTPoison.post "https://bd-partner-a-system.blackboard.com/learn/api/public/v1/oauth2/token", "grant_type=client_credentials", [{"Content-Type", "application/x-www-form-urlencoded"}], [hackney: [basic_auth: {"user", "password"}] ]
The code is :ok, or not. The response will be an %HTTPoison.Response
HTTPotion POST Example. Most everything, including auth, goes into options.
response = HTTPotion.post(url, options \\ [])
iex(2)> options = [body: "grant_type=client_credentials",
headers: ["Content-Type": "application/x-www-form-urlencoded"],
basic_auth: {"user","password"}]
iex(3)>response = HTTPotion.post("https://bd-partner-a-system.blackboard.com", options)
The response will be an %HTTPotion.Response.
Docs are easily found with a search. Between the docs you find and the above examples, you should be set!
Linuus
Have you looked at the documentation?
Here’s the post function: HTTPoison — HTTPoison v3.0.0
Something along these lines is what you want to do:
case HTTPoison.post(url, body, headers) do
{:ok, response} -> IO.inspect(response) # Request went through, do something :)
{:error, reason} -> IO.inspect(reason) # Request failed...
end
Also: GitHub - edgurgel/httpoison: Yet Another HTTP client for Elixir powered by hackney · GitHub








