Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple example using Erlang for https post

Tags:

https

ssl

erlang

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.

like image 549
RockyMountainHigh Avatar asked Sep 30 '13 20:09

RockyMountainHigh


1 Answers

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'}"
    }, [], []).
like image 126
Zachary Orr Avatar answered Nov 15 '22 00:11

Zachary Orr