Main MRPT website > C++ reference
MRPT logo
net_utils.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef MRPT_NET_UTILS_H
29 #define MRPT_NET_UTILS_H
30 
33 #include <mrpt/utils/TParameters.h>
34 
35 namespace mrpt
36 {
37  namespace utils
38  {
39  /** A set of useful routines for networking.
40  * \ingroup network_grp
41  */
42  namespace net
43  {
44  /** \addtogroup network_grp
45  * @{ */
46 
47  using std::string;
48 
49  /** Possible returns from a HTTP request.
50  */
52  erOk = 0,
57  };
58 
59  /** Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
60  * \param url Must be a simple string of the form "http://<servername>/<relative-address>".
61  * \param port The server port, if different from 80.
62  * \param extra_headers If provided, the given extra HTTP headers will be sent.
63  * \param out_errormsg On exit will contain a description of the error or "Ok".
64  * \param out_content The buffer with the retrieved data.
65  * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200, 404...
66  * \param out_headers If provided, a copy of all the headers returned by the server will be saved here.
67  * \param auth_user Send a basic HTTP authorization request with the given user & password.
68  * \param auth_pass Send a basic HTTP authorization request with the given user & password.
69  *
70  * \return The error or success code.
71  * \sa mrpt::utils::vectorToBinaryFile
72  */
74  http_get(
75  const string &url,
76  vector_byte &out_content,
77  string &out_errormsg,
78  int port = 80,
79  const string &auth_user = string(),
80  const string &auth_pass = string(),
81  int *out_http_responsecode = NULL,
82  mrpt::utils::TParameters<string> *extra_headers = NULL,
83  mrpt::utils::TParameters<string> *out_headers = NULL,
84  int timeout_ms = 1000
85  );
86 
87  /** Perform an HTTP GET operation (version for retrieving the data as text)
88  * \param url Must be a simple string of the form "http://<servername>/<relative-address>".
89  * \param port The server port, if different from 80.
90  * \param extra_headers If provided, the given extra HTTP headers will be sent.
91  * \param out_errormsg On exit will contain a description of the error or "Ok".
92  * \param out_content The buffer with the retrieved data.
93  * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200, 404...
94  * \param out_headers If provided, a copy of all the headers returned by the server will be saved here.
95  * \param auth_user Send a basic HTTP authorization request with the given user & password.
96  * \param auth_pass Send a basic HTTP authorization request with the given user & password.
97  *
98  * \return The error or success code.
99  * \sa mrpt::utils::vectorToBinaryFile
100  */
102  http_get(
103  const string &url,
104  string &out_content,
105  string &out_errormsg,
106  int port = 80,
107  const string &auth_user = string(),
108  const string &auth_pass = string(),
109  int *out_http_responsecode = NULL,
110  mrpt::utils::TParameters<string> *extra_headers = NULL,
111  mrpt::utils::TParameters<string> *out_headers = NULL,
112  int timeout_ms = 1000
113  );
114 
115 
116  /** Resolve a server address by its name, returning its IP address as a string - This method has a timeout for the maximum time to wait for the DNS server.
117  * For example: server_name="www.google.com" -> out_ip="209.85.227.99"
118  *
119  * \return true on success, false on timeout or other error.
120  */
121  bool DNS_resolve_async(
122  const std::string &server_name,
123  std::string &out_ip,
124  const unsigned int timeout_ms = 3000
125  );
126 
127  /** @} */ // end grouping
128 
129  } // End of namespace
130  } // End of namespace
131 } // end of namespace
132 
133 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013