簡體   English   中英

http 發布請求 erlang

[英]http post request erlang

我有幾個函數可以執行 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, [], []).
Body = "name=<<name>>&pass=<<pass>>",
httpc:request(post, {Url, [], "application/x-www-form-urlencoded", Body}, [], []).

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM