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.