2011-05-30 88 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}, [], []).