2011-05-30 81 views
5

我有几个执行HTTP POST/GET/HEAD请求的函数。http post request erlang

因为我用这个POST请求:

http:request(post, {Url, [], ContentType, Body}, [], []). 

虽然头/ GET我用:

http:request(Method, {Url, []}, [], []) 

我怎么能写在一个独特的一本两个电话? POST请求具有关于GET/HEAD请求的这两个附加变量。我试着用空列表,但我得到:

** exception error: no function clause matching 

非常感谢您

回答

8

只有一次使用调用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, [], []). 
2
Body = "name=<<name>>&pass=<<pass>>", 
httpc:request(post, {Url, [], "application/x-www-form-urlencoded", Body}, [], []).