valpackett / httpotion

[Deprecated because ibrowse is not maintained] HTTP client for Elixir (use Tesla please)
https://hexdocs.pm/httpotion/readme.html
The Unlicense
725 stars 100 forks source link

Provide example of sending nested form data #103

Closed timkellogg closed 7 years ago

timkellogg commented 7 years ago

It would be great to have an example of how to properly form a request with nested data.

endpoint = "http://localhost:8080/form"
headers = ["User-Agent": "Mozilla/5/0...",  "Content-Type": "application/x-www-form-urlencoded"]

HTTPotion.post endpoint, [body: [model: [attribute_one: value_one, attribute_two: value_two]], headers: headers]

It's not entirely clear why this doesn't work. This is the resulting error message: (Protocol.UndefinedError) protocol String.Chars not implemented for %HTTPotion.ErrorResponse

valpackett commented 7 years ago

You have to run the form encoding function yourself.

I wonder how you got the idea that you can pass various objects as the body — all examples in the readme are clearly passing strings, there's even this example: "hello=" <> URI.encode_www_form("w o r l d !!")

Is there a way to make this clearer in the readme?

timkellogg commented 7 years ago

Ah ok, thanks for the response. I would have been helped by what you just said now. Thanks