Trying to change Content-Type in a POST request using HTTPoison

Hello all, I’m trying to make a POST request using HTTPoison, where I need to set the Content-Type header.

According to this test, this should let us set the Content-Type to multipart/form-data:

HTTPoison.post "https://validator.nu", {:form, [doc: "HTML"]}, [{"Content-Type", "multipart/form-data"}]

…but it doesn’t. At least, the server complains with “application/x-www-form-urlencoded not supported. Please use multipart/form-data.”.

I’ve also tried posting it to https://httpbin.org/post, which reflects back what you send it, and I don’t see this header being set.

What am I doing wrong?

3 Likes

Solved in Slack by @sschneider – this is the correct way to send a multipart form:

HTTPoison.post("https://validator.nu/", {:multipart, [{"out", "json"}, {"content", "HTML"}]})

Thanks!

3 Likes