I have found quote a few examples of using erlang with ssl (via rpc) and http get's etc. But I am having a hard time finding an example of posting data to an ssl endpoint via erlang. Does anybody know of a simple example that I am missing?
I think I figured it out. I had the arguments wrong. This is what I ended-up with for a post:
httpc:request(post, {"https://localhost:2840", [], [], ["Test"]}, [], [])
Appears to be working. But my server is crashing now. So, maybe not.
You'll need to start ssl and inets before you send the request. Depending on the type of data you're trying to post, it'll have to be formatted differently. My example shows urlencoded data
ssl:start(),
application:start(inets),
httpc:request(post,
{"https://postman-echo.com/post", [],
"application/x-www-form-urlencoded",
"example=here&foo=bar"
}, [], []).
A JSON request would look like
ssl:start(),
application:start(inets),
httpc:request(post,
{"https://postman-echo.com/post", [],
"application/json",
"{'example':'here', 'foo':'bar'}"
}, [], []).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With