Erlang [novice] grow diary HTTP client

1 Start

Method 1: Start inets application, a default profile management process will be started.

inets:start().

Second way: run-time, dynamic start profile stop profile.

Dynamic start profile:

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

Dynamic stop profile:

inets:stop(httpc, foo).

or

inets:stop(httpc, Pid).

 

2, Set

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

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

 

3, the request

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

Synchronization request:

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

Equivalent to

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

Asynchronous request:

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

Reproduced in: https: //www.cnblogs.com/dyingbleed/archive/2012/09/05/2672545.html

Guess you like

Origin blog.csdn.net/weixin_33716154/article/details/93301806