【问题标题】:Simple example using Erlang for https post使用 Erlang 进行 https 帖子的简单示例
【发布时间】:2013-10-06 21:00:47
【问题描述】:

我找到了一些使用 erlang 与 ssl(通过 rpc)和 http get 等的示例。但是我很难找到通过 erlang 将数据发布到 ssl 端点的示例。有人知道我缺少的一个简单示例吗?

我想我明白了。我的论点是错误的。这就是我最终的帖子:

httpc:request(post, {"https://localhost:2840", [], [], ["Test"]}, [], [])

似乎正在工作。但是我的服务器现在崩溃了。所以,也许不是。

【问题讨论】:

  • 我发现了,但这不是帖子,我在文档中找不到需要如何设置正文。
  • 而且这似乎也已经过时了,因为 http 已被 httpc 取代。不过谢谢你的回复。
  • 是的,很抱歉。你在使用 httpc 时遇到了什么问题?您能用您尝试过的方法更新您的问题吗?
  • 服务器日志说了什么?

标签: ssl https erlang


【解决方案1】:

您需要在发送请求之前启动 ssl 和 inets。根据您尝试发布的数据类型,必须采用不同的格式。我的示例显示了 urlencoded 数据

ssl:start(),
application:start(inets),
httpc:request(post, 
    {"https://postman-echo.com/post", [], 
    "application/x-www-form-urlencoded",
    "example=here&foo=bar"
    }, [], []).

JSON 请求看起来像

ssl:start(),
application:start(inets),
httpc:request(post,
    {"https://postman-echo.com/post", [],
    "application/json",
    "{'example':'here', 'foo':'bar'}"
    }, [], []).

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-19
    • 2011-10-12
    • 2011-12-31
    • 2020-08-17
    • 1970-01-01
    • 2011-02-22
    • 2014-07-18
    • 1970-01-01
    相关资源
    最近更新 更多