使用Erlang进行https发布的简单示例 [英] Simple example using Erlang for https post

查看:156
本文介绍了使用Erlang进行https发布的简单示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到一些使用ssl(通过rpc)和http get等使用erlang的例子。但是我很难找到通过erlang将数据发布到ssl端点的例子。有没有人知道我失踪的一个简单的例子?

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.

推荐答案

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

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, 
    {"http://requestb.in/ofjf4iof", [], 
    "application/x-www-form-urlencoded",
    "example=here&foo=bar"
    }, [], []).

对于JSON文章的示例,您可以查看 here

For an example of a JSON post, you can look here

这篇关于使用Erlang进行https发布的简单示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆