42
42
dynamically in runtime. Each client profile will spawn a new
43
43
process to handle each request unless there is a possibility to use
44
44
a persistent connection with or without pipelining.
45
The client will add a host header and an empty
46
te header if there are no such headers present in the request.</p>
45
The client will add a <c>host</c> header and an empty
46
<c>te</c> header if there are no such headers present in the request.</p>
48
<p>The clients supports ipv6 as long as the underlying mechanisms also do
48
<p>The client supports ipv6 as long as the underlying mechanisms also do
71
71
but not for requests to localhost. This will apply to all subsequent
74
2 > http:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},
74
2 > httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},
78
78
<p>An ordinary synchronous request. </p>
80
80
3 > {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
81
http:request(get, {"http://www.erlang.org", []}, [], []).
81
httpc:request(get, {"http://www.erlang.org", []}, [], []).
83
83
<p>With all default values, as above, a get request can also be written
86
86
4 > {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
87
http:request("http://www.erlang.org").
87
httpc:request("http://www.erlang.org").
89
89
<p>An ordinary asynchronous request. The result will be sent
90
to the calling process on the form {http, {ReqestId, Result}}</p>
90
to the calling process in the form <c>{http, {ReqestId, Result}}</c></p>
92
92
5 > {ok, RequestId} =
93
http:request(get, {"http://www.erlang.org", []}, [], [{sync, false}]).
93
httpc:request(get, {"http://www.erlang.org", []}, [], [{sync, false}]).
95
95
<p>In this case the calling process is the shell, so we receive the
98
6 > receive {http, {RequestId, Result}} -> ok after 500 -> error end.
98
6 > receive {http, {RequestId, Result}} -> ok after 500 -> error end.
101
101
<p>Send a request with a specified connection header. </p>
102
102
<code type="erl">
103
103
7 > {ok, {{NewVersion, 200, NewReasonPhrase}, NewHeaders, NewBody}} =
104
http:request(get, {"http://www.erlang.org", [{"connection", "close"}]},
104
httpc:request(get, {"http://www.erlang.org", [{"connection", "close"}]},
108
108
<p>Start a HTTP client profile. </p>
111
8 > {ok, Pid} = inets:start(httpc, [{profile, foo}]).
111
8 > {ok, Pid} = inets:start(httpc, [{profile, foo}]).
115
115
<p>The new profile has no proxy settings so the connection will
117
117
<code type="erl">
118
9 > http:request("http://www.erlang.org", foo).
118
9 > httpc:request("http://www.erlang.org", foo).
119
{error, econnrefused}
122
122
<p>Stop a HTTP client profile. </p>
123
123
<code type="erl">
124
10 > inets:stop(httpc, foo).
124
10 > inets:stop(httpc, foo).
128
128
<p>Alternatively:</p>
129
129
<code type="erl">
130
10 > inets:stop(httpc, Pid).
130
10 > inets:stop(httpc, Pid).