Simple example using Erlang for https post

后端 未结 1 1646
北恋
北恋 2021-02-15 02:08

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 e

相关标签:
1条回答
  • 2021-02-15 02:33

    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'}"
        }, [], []).
    
    0 讨论(0)
提交回复
热议问题