Main MRPT website > C++ reference for MRPT 1.5.9
net_utils.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef MRPT_NET_UTILS_H
10 #define MRPT_NET_UTILS_H
11 
12 #include <mrpt/utils/core_defs.h>
14 #include <mrpt/utils/TParameters.h>
15 
16 namespace mrpt
17 {
18  namespace utils
19  {
20  /** A set of useful routines for networking. (in #include <mrpt/utils/net_utils.h>)
21  * \ingroup network_grp
22  */
23  namespace net
24  {
25  /** \addtogroup network_grp
26  * @{ */
27 
28  using std::string;
29 
30  /** Possible returns from a HTTP request. */
32  erOk = 0,
37  };
38 
39  /** Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
40  * \param url Must be a simple string of the form "http://<servername>/<relative-address>".
41  * \param port The server port, if different from 80.
42  * \param extra_headers If provided, the given extra HTTP headers will be sent.
43  * \param out_errormsg On exit will contain a description of the error or "Ok".
44  * \param out_content The buffer with the retrieved data.
45  * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200, 404...
46  * \param out_headers If provided, a copy of all the headers returned by the server will be saved here.
47  * \param auth_user Send a basic HTTP authorization request with the given user & password.
48  * \param auth_pass Send a basic HTTP authorization request with the given user & password.
49  *
50  * \return The error or success code.
51  * \sa mrpt::utils::vectorToBinaryFile
52  */
54  http_get(
55  const string &url,
56  vector_byte &out_content,
57  string &out_errormsg,
58  int port = 80,
59  const string &auth_user = string(),
60  const string &auth_pass = string(),
61  int *out_http_responsecode = NULL,
62  mrpt::utils::TParameters<string> *extra_headers = NULL,
63  mrpt::utils::TParameters<string> *out_headers = NULL,
64  int timeout_ms = 1000
65  );
66 
67  /** Perform an HTTP GET operation (version for retrieving the data as text)
68  * \param url Must be a simple string of the form "http://<servername>/<relative-address>".
69  * \param port The server port, if different from 80.
70  * \param extra_headers If provided, the given extra HTTP headers will be sent.
71  * \param out_errormsg On exit will contain a description of the error or "Ok".
72  * \param out_content The buffer with the retrieved data.
73  * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200, 404...
74  * \param out_headers If provided, a copy of all the headers returned by the server will be saved here.
75  * \param auth_user Send a basic HTTP authorization request with the given user & password.
76  * \param auth_pass Send a basic HTTP authorization request with the given user & password.
77  *
78  * \return The error or success code.
79  * \sa mrpt::utils::vectorToBinaryFile
80  */
82  http_get(
83  const string &url,
84  string &out_content,
85  string &out_errormsg,
86  int port = 80,
87  const string &auth_user = string(),
88  const string &auth_pass = string(),
89  int *out_http_responsecode = NULL,
90  mrpt::utils::TParameters<string> *extra_headers = NULL,
91  mrpt::utils::TParameters<string> *out_headers = NULL,
92  int timeout_ms = 1000
93  );
94 
95  /** Generic function for HTTP GET & POST methods. \sa http_get */
98  const string & http_method,
99  const string & http_send_content,
100  const string &url,
101  vector_byte &out_content,
102  string &out_errormsg,
103  int port = 80,
104  const string &auth_user = string(),
105  const string &auth_pass = string(),
106  int *out_http_responsecode = NULL,
107  mrpt::utils::TParameters<string> *extra_headers = NULL,
108  mrpt::utils::TParameters<string> *out_headers = NULL,
109  int timeout_ms = 1000
110  );
111 
112 
113  /** Resolve a server address by its name, returning its IP address as a
114  * string - This method has a timeout for the maximum time to wait for
115  * the DNS server. For example: server_name="www.google.com" ->
116  * out_ip="209.85.227.99"
117  *
118  * \return true on success, false on timeout or other error.
119  */
121  const std::string &server_name,
122  std::string &out_ip,
123  const unsigned int timeout_ms = 3000
124  );
125 
126  /** Returns a description of the last Sockets error */
128 
129  /** @brief Ping an IP address
130  *
131  * @param[in] address Address to ping.
132  * @param[in] max_attempts Number of attempts to try and ping.
133  * @param[out] output String containing output information
134  *
135  * @return True if responsive, false otherwise.
136  *
137  * @note { I am redirecting stderr to stdout, so that the overall process
138  * is simplified. Otherwise see:
139  * https://jineshkj.wordpress.com/2006/12/22/how-to-capture-stdin-stdout-and-stderr-of-child-program/
140  * }
141  *
142  */
143  bool BASE_IMPEXP Ping(
144  const std::string& address,
145  const int& max_attempts,
146  std::string* output_str=NULL);
147 
148  /** @} */ // end grouping
149 
150  } // End of namespace
151  } // End of namespace
152 } // end of namespace
153 
154 #endif
ERRORCODE_HTTP
Possible returns from a HTTP request.
Definition: net_utils.h:31
For usage when passing a dynamic number of (numeric) arguments to a function, by name.
Definition: TParameters.h:51
std::vector< uint8_t > vector_byte
Definition: types_simple.h:26
ERRORCODE_HTTP BASE_IMPEXP http_get(const string &url, vector_byte &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=NULL, mrpt::utils::TParameters< string > *extra_headers=NULL, mrpt::utils::TParameters< string > *out_headers=NULL, int timeout_ms=1000)
Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
Definition: net_utils.cpp:388
std::string BASE_IMPEXP getLastSocketErrorStr()
Returns a description of the last Sockets error.
Definition: net_utils.cpp:519
GLsizei const GLchar ** string
Definition: glext.h:3919
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool BASE_IMPEXP Ping(const std::string &address, const int &max_attempts, std::string *output_str=NULL)
Ping an IP address.
Definition: net_utils.cpp:538
bool BASE_IMPEXP DNS_resolve_async(const std::string &server_name, std::string &out_ip, const unsigned int timeout_ms=3000)
Resolve a server address by its name, returning its IP address as a string - This method has a timeou...
Definition: net_utils.cpp:430
ERRORCODE_HTTP BASE_IMPEXP http_request(const string &http_method, const string &http_send_content, const string &url, vector_byte &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=NULL, mrpt::utils::TParameters< string > *extra_headers=NULL, mrpt::utils::TParameters< string > *out_headers=NULL, int timeout_ms=1000)
Generic function for HTTP GET & POST methods.
Definition: net_utils.cpp:78
GLuint address
Definition: glext.h:6078



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020