RockyMountainHigh
RockyMountainHigh

Reputation: 3021

Simple example using Erlang for https post

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.

Upvotes: 9

Views: 10828

Answers (1)

Zachary Orr
Zachary Orr

Reputation: 1751

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'}"
    }, [], []).

Upvotes: 13

Related Questions