http发布请求erlang

use*_*836 5 erlang http

我有几个执行HTTP POST/GET/HEAD请求的函数.

对于POST请求,我使用:

  http:request(post, {Url, [], ContentType, Body}, [], []).
Run Code Online (Sandbox Code Playgroud)

而对于HEAD/GET,我使用:

  http:request(Method, {Url, []}, [], [])
Run Code Online (Sandbox Code Playgroud)

如何以独特的方式编写这两个电话?POST请求具有与GET/HEAD请求相关的那两个附加变量.我尝试使用空列表,但我得到了:

  ** exception error: no function clause matching
Run Code Online (Sandbox Code Playgroud)

非常感谢你

Ada*_*erg 9

httpc仅将调用用于一次,您需要Request从调用中提取元组,因为这是在使用它们时方法之间的唯一性:

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, [], []).
Run Code Online (Sandbox Code Playgroud)