4
4
HTTP client
5
5
*************
6
6
7
- .. todo ::
8
-
9
- Rewrite text, provide a CLI example.
10
-
11
7
The first code example is the simplest thing you can do with the
12
8
:mod: `cpp-netlib `. The application is a simple HTTP client, which can
13
9
be found in the subdirectory ``libs/network/example/http_client.cpp ``.
14
10
All we are doing is creating and sending an HTTP request to a server
15
- and printing the response body. Without further ado, the code to do
16
- this is as follows:
11
+ and printing the response body.
12
+
13
+ The Code
14
+ ========
15
+
16
+ Without further ado, the code to do this is as follows:
17
17
18
18
.. code-block :: c++
19
19
20
20
#include <boost/network/protocol/http/client.hpp>
21
21
#include <iostream>
22
22
23
- int
24
- main(int argc, char *argv[]) {
23
+ int main(int argc, char *argv[]) {
25
24
using namespace boost::network;
26
25
27
26
if (argc != 2) {
@@ -38,6 +37,29 @@ this is as follows:
38
37
return 0;
39
38
}
40
39
40
+ Building and Running The Code
41
+ =============================
42
+
43
+ To be build this example, you can follow the steps below without having to build
44
+ the whole :mod: `cpp-netlib ` distribution::
45
+
46
+ $ cd ~/cpp-netlib
47
+ $ g++ -o http_client1 libs/network/example/http_client1.cpp \
48
+ > -I. \
49
+ > -I$BOOST_ROOT \
50
+ > -L$BOOST_ROOT/stage/lib \
51
+ > -lboost_system \
52
+ > -pthread
53
+
54
+ You can then run this to get the Boost _ website::
55
+
56
+ $ ./http_client1 http://www.boost.org/
57
+
58
+ .. _Boost : http://www.boost.org/
59
+
60
+ Diving into the Code
61
+ ====================
62
+
41
63
Since this is the first example, each line will be presented and
42
64
explained in detail.
43
65
@@ -51,7 +73,7 @@ All the code needed for the HTTP client resides in this header.
51
73
52
74
http::client client;
53
75
54
- First we create a ``client `` object. The ``client `` contains all the
76
+ First we create a ``client `` object. The ``client `` abstracts all the
55
77
connection and protocol logic. The default HTTP client is version
56
78
1.1, as specified in `RFC 2616 `_.
57
79
0 commit comments