http post请求erlang [英] http post request erlang
本文介绍了http post请求erlang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个功能可以执行HTTP POST / GET / HEAD请求。
I have a couple of functions that perform HTTP POST/GET/HEAD requests.
对于POST请求,我使用:
For the POST request I use this:
http:request(post, {Url, [], ContentType, Body}, [], []).
对于HEAD / GET,我使用:
While for the HEAD/GET I use:
http:request(Method, {Url, []}, [], [])
如何将这两个电话写入独一无二的电话? POST请求具有关于GET / HEAD请求的两个附加变量。我尝试用空列表,但我得到:
How can I write this two calls in a unique one? POST request has those two additional variables with respect to GET/HEAD request. I tried with empty lists but I got:
** exception error: no function clause matching
非常感谢
推荐答案
要使用 httpc
调用一次,您需要从调用中提取 Request
元组,因为这是独特的使用它们的方法:
To use the call to httpc
only once, you need to extract the Request
tuple from the call because that's what's unique between the methods as you use them:
post(URL, ContentType, Body) -> request(post, {URL, [], ContentType, Body}).
get(URL) -> request(get, {URL, []}).
head(URL) -> request(head, {URL, []}).
request(Method, Request) ->
httpc:request(Method, Request, [], []).
这篇关于http post请求erlang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文