【Erlang新手成長日記】HTTP客戶端


1、啟動

方式一:啟動inets應用,一個缺省profile的管理進程將被啟動。

inets:start().

方式二:運行時,動態啟動profile停止profile。

動態啟動profile:

{ok, Pid} = inets:start(httpc, [{profile, foo}]).

動態停止profile:

inets:stop(httpc, foo).

inets:stop(httpc, Pid).

 

2、設置

httpc:set_options() -> ok | {error, Reason}

參考:http://www.erlang.org/doc/man/httpc.html#set_options-1

 

3、請求

參考:http://www.erlang.org/doc/man/httpc.html#request-1

同步請求:

{ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request("http://www.baidu.com").

等同於

{ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request(get, {"http://www.baidu.com", []}, [], []).

異步請求:

{ok, RequestId} = httpc:request(get, {"http://www.baidu.com", []}, [], [{sync, false}]),
receive {http, {RequestId, Result}} -> ok after 500 -> error end.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM