~statik/ubuntu/maverick/erlang/erlang-merge-testing

« back to all changes in this revision

Viewing changes to lib/inets/doc/src/http_client.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-05-01 10:14:38 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090501101438-6qlr6rsdxgyzrg2z
Tags: 1:13.b-dfsg-2
* Cleaned up patches: removed unneeded patch which helped to support
  different SCTP library versions, made sure that changes for m68k
  architecture applied only when building on this architecture.
* Removed duplicated information from binary packages descriptions.
* Don't require libsctp-dev build-dependency on solaris-i386 architecture
  which allows to build Erlang on Nexenta (thanks to Tim Spriggs for
  the suggestion).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
 
3
 
 
4
<chapter>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>2004</year><year>2009</year>
 
8
      <holder>Ericsson AB. All Rights Reserved.</holder>
 
9
    </copyright>
 
10
    <legalnotice>
 
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/.
 
16
    
 
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
 
20
      under the License.
 
21
    
 
22
    </legalnotice>
 
23
 
 
24
    <title>HTTP Client</title>
 
25
    <prepared>Ingela Anderton Andin</prepared>
 
26
    <responsible></responsible>
 
27
    <docno></docno>
 
28
    <approved></approved>
 
29
    <checked></checked>
 
30
    <date></date>
 
31
    <rev></rev>
 
32
    <file></file>
 
33
  </header>
 
34
 
 
35
  <section>
 
36
    <title>Introduction</title>
 
37
 
 
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>
 
47
 
 
48
    <p>The clients supports ipv6 as long as the underlying mechanisms also do
 
49
      so.</p>
 
50
  </section>
 
51
 
 
52
  <section>
 
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>
 
56
    <pre>
 
57
      [{inets, [{services, [{httpc, PropertyList}]}]}]
 
58
    </pre>
 
59
    <p>For valid properties see <seealso
 
60
                               marker="http">http(3)</seealso></p>
 
61
  </section>
 
62
 
 
63
  <section>
 
64
    <title>Using the HTTP Client API</title>
 
65
    <code type="erl">
 
66
 1 > inets:start().
 
67
      ok
 
68
    </code>
 
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
 
72
      requests</p>
 
73
    <code type="erl">
 
74
      2 > http:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},
 
75
      ["localhost"]}}]).
 
76
      ok
 
77
    </code>
 
78
    <p>An ordinary synchronous request. </p>
 
79
    <code type="erl">
 
80
      3 > {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
 
81
      http:request(get, {"http://www.erlang.org", []}, [], []).
 
82
    </code>
 
83
    <p>With all default values, as above, a get request can also be written
 
84
      like this.</p>
 
85
    <code type="erl">
 
86
      4 > {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
 
87
      http:request("http://www.erlang.org").
 
88
    </code>
 
89
    <p>An ordinary asynchronous request. The result will be sent
 
90
      to the calling process on the form {http, {ReqestId, Result}}</p>
 
91
    <code type="erl">
 
92
      5 > {ok, RequestId} =
 
93
      http:request(get, {"http://www.erlang.org", []}, [], [{sync, false}]).
 
94
    </code>
 
95
    <p>In this case the calling process is the shell, so we receive the
 
96
      result.</p>
 
97
    <code type="erl">
 
98
      6 >  receive {http, {RequestId, Result}} -> ok after 500 -> error end.
 
99
      ok
 
100
    </code>
 
101
    <p>Send a request with a specified connection header. </p>
 
102
    <code type="erl">
 
103
      7 > {ok, {{NewVersion, 200, NewReasonPhrase}, NewHeaders, NewBody}} =
 
104
      http:request(get, {"http://www.erlang.org", [{"connection", "close"}]},
 
105
      [], []).
 
106
    </code>
 
107
 
 
108
    <p>Start a HTTP client profile. </p>
 
109
   
 
110
    <code><![CDATA[
 
111
      8 >  {ok, Pid} = inets:start(httpc, [{profile, foo}]).
 
112
      {ok, <0.45.0>}       
 
113
      ]]></code>
 
114
    
 
115
    <p>The new profile has no proxy settings so the connetion will
 
116
      be refused</p>
 
117
      <code type="erl">
 
118
      9 > http:request("http://www.erlang.org", foo).              
 
119
      {error,econnrefused}
 
120
    </code>
 
121
 
 
122
    <p>Stop a HTTP client profile. </p>
 
123
    <code type="erl">
 
124
      10 >  inets:stop(httpc, foo).
 
125
      ok
 
126
    </code>
 
127
    
 
128
    <p>Alternatively:</p>
 
129
    <code type="erl">
 
130
      10 >  inets:stop(httpc, Pid).
 
131
      ok
 
132
    </code>
 
133
    
 
134
    
 
135
  </section>
 
136
</chapter>
 
137
 
 
138
 
 
139
 
 
140