我有几个执行 HTTP POST/GET/HEAD 请求的函数。
对于 POST 请求,我使用这个:
http:request(post, {Url, [], ContentType, Body}, [], []).
对于 HEAD/GET 我使用:
http:request(Method, {Url, []}, [], [])
我怎样才能将这两个调用写在一个唯一的调用中? POST 请求具有相对于 GET/HEAD 请求的这两个附加变量。我尝试使用空列表,但得到:
** exception error: no function clause matching
非常感谢。
要使用调用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, [], []).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)