1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
7
<year>2004</year><year>2009</year>
8
<holder>Ericsson AB. All Rights Reserved.</holder>
11
The contents of this file are subject to the Erlang Public License,
12
Version 1.1, (the "License"); you may not use this file except in
13
compliance with the License. You should have received a copy of the
14
Erlang Public License along with this software. If not, it can be
15
retrieved online at http://www.erlang.org/.
17
Software distributed under the License is distributed on an "AS IS"
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
the License for the specific language governing rights and limitations
24
<title>HTTP Client</title>
25
<prepared>Ingela Anderton Andin</prepared>
26
<responsible></responsible>
36
<title>Introduction</title>
38
<p>The HTTP client default profile will be started when the inets
39
application is started and is then available to all processes on
40
that erlang node. Other profiles may also be started at
41
application startup, or profiles can be started and stopped
42
dynamically in runtime. Each client profile will spawn a new
43
process to handle each request unless there is a possibility to use
44
a persistent connection with or without pipeling.
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>
48
<p>The clients supports ipv6 as long as the underlying mechanisms also do
53
<title>Configuration</title>
54
<p> What to put in the erlang node application configuration file
55
in order to start a profile at application startup.</p>
57
[{inets, [{services, [{httpc, PropertyList}]}]}]
59
<p>For valid properties see <seealso
60
marker="http">http(3)</seealso></p>
64
<title>Using the HTTP Client API</title>
69
<p> The following calls uses the default client profile.
70
Use the proxy "www-proxy.mycompany.com:8000",
71
but not for requsts to localhost. This will apply to all subsequent
74
2 > http:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},
78
<p>An ordinary synchronous request. </p>
80
3 > {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
81
http:request(get, {"http://www.erlang.org", []}, [], []).
83
<p>With all default values, as above, a get request can also be written
86
4 > {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
87
http:request("http://www.erlang.org").
89
<p>An ordinary asynchronous request. The result will be sent
90
to the calling process on the form {http, {ReqestId, Result}}</p>
93
http:request(get, {"http://www.erlang.org", []}, [], [{sync, false}]).
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.
101
<p>Send a request with a specified connection header. </p>
103
7 > {ok, {{NewVersion, 200, NewReasonPhrase}, NewHeaders, NewBody}} =
104
http:request(get, {"http://www.erlang.org", [{"connection", "close"}]},
108
<p>Start a HTTP client profile. </p>
111
8 > {ok, Pid} = inets:start(httpc, [{profile, foo}]).
115
<p>The new profile has no proxy settings so the connetion will
118
9 > http:request("http://www.erlang.org", foo).
122
<p>Stop a HTTP client profile. </p>
124
10 > inets:stop(httpc, foo).
128
<p>Alternatively:</p>
130
10 > inets:stop(httpc, Pid).