【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.

转载于:https://www.cnblogs.com/dyingbleed/archive/2012/09/05/2672545.html

猜你喜欢

转载自blog.csdn.net/weixin_33716154/article/details/93301806