Main MRPT website > C++ reference for MRPT 1.9.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-2018, 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 #pragma once
10 
11 #include <string>
12 #include <vector>
14 
15 namespace mrpt
16 {
17 namespace comms
18 {
19 /** A set of useful routines for networking. (in #include
20  * <mrpt/comms/net_utils.h>)
21  * \ingroup mrpt_comms_grp
22  */
23 namespace net
24 {
25 /** \addtogroup mrpt_comms_grp
26  * @{ */
27 
28 using std::string;
29 
30 /** Possible returns from a HTTP request. */
32 {
33  erOk = 0,
38 };
39 
40 /** Perform an HTTP GET operation (version for retrieving the data as a
41  * std::vector<uint8_t>)
42  * \param url Must be a simple string of the form
43  * "http://<servername>/<relative-address>".
44  * \param port The server port, if different from 80.
45  * \param extra_headers If provided, the given extra HTTP headers will be sent.
46  * \param out_errormsg On exit will contain a description of the error or "Ok".
47  * \param out_content The buffer with the retrieved data.
48  * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200,
49  * 404...
50  * \param out_headers If provided, a copy of all the headers returned by the
51  * server will be saved here.
52  * \param auth_user Send a basic HTTP authorization request with the given user
53  * & password.
54  * \param auth_pass Send a basic HTTP authorization request with the given user
55  * & password.
56  *
57  * \return The error or success code.
58  * \sa http_request()
59  */
61  const string& url, std::vector<uint8_t>& out_content, string& out_errormsg,
62  int port = 80, const string& auth_user = string(),
63  const string& auth_pass = string(), int* out_http_responsecode = nullptr,
64  mrpt::system::TParameters<string>* extra_headers = nullptr,
65  mrpt::system::TParameters<string>* out_headers = nullptr,
66  int timeout_ms = 1000);
67 
68 /** Perform an HTTP GET operation (version for retrieving the data as text)
69  * \param url Must be a simple string of the form
70  * "http://<servername>/<relative-address>".
71  * \param port The server port, if different from 80.
72  * \param extra_headers If provided, the given extra HTTP headers will be sent.
73  * \param out_errormsg On exit will contain a description of the error or "Ok".
74  * \param out_content The buffer with the retrieved data.
75  * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200,
76  * 404...
77  * \param out_headers If provided, a copy of all the headers returned by the
78  * server will be saved here.
79  * \param auth_user Send a basic HTTP authorization request with the given user
80  * & password.
81  * \param auth_pass Send a basic HTTP authorization request with the given user
82  * & password.
83  *
84  * \return The error or success code.
85  * \sa http_request()
86  */
88  const string& url, string& out_content, string& out_errormsg, int port = 80,
89  const string& auth_user = string(), const string& auth_pass = string(),
90  int* out_http_responsecode = nullptr,
91  mrpt::system::TParameters<string>* extra_headers = nullptr,
92  mrpt::system::TParameters<string>* out_headers = nullptr,
93  int timeout_ms = 1000);
94 
95 /** Generic function for HTTP GET & POST methods. \sa http_get */
97  const string& http_method, const string& http_send_content,
98  const string& url, std::vector<uint8_t>& out_content, string& out_errormsg,
99  int port = 80, const string& auth_user = string(),
100  const string& auth_pass = string(), int* out_http_responsecode = nullptr,
101  mrpt::system::TParameters<string>* extra_headers = nullptr,
102  mrpt::system::TParameters<string>* out_headers = nullptr,
103  int timeout_ms = 1000);
104 
105 /** Resolve a server address by its name, returning its IP address as a
106  * string - This method has a timeout for the maximum time to wait for
107  * the DNS server. For example: server_name="www.google.com" ->
108  * out_ip="209.85.227.99"
109  *
110  * \return true on success, false on timeout or other error.
111  */
112 bool DNS_resolve_async(
113  const std::string& server_name, std::string& out_ip,
114  const unsigned int timeout_ms = 3000);
115 
116 /** Returns a description of the last Sockets error */
118 
119 /** @brief Ping an IP address
120  *
121  * @param[in] address Address to ping.
122  * @param[in] max_attempts Number of attempts to try and ping.
123  * @param[out] output String containing output information
124  *
125  * @return True if responsive, false otherwise.
126  *
127  * @note { I am redirecting stderr to stdout, so that the overall process
128  * is simplified. Otherwise see:
129  * https://jineshkj.wordpress.com/2006/12/22/how-to-capture-stdin-stdout-and-stderr-of-child-program/
130  * }
131  *
132  */
133 bool Ping(
134  const std::string& address, const int max_attempts,
135  std::string* output_str = NULL);
136 
137 /** @} */ // end grouping
138 
139 } // End of namespace
140 } // End of namespace
141 } // end of namespace
mrpt::comms::net::erOtherHTTPError
@ erOtherHTTPError
Definition: net_utils.h:37
address
GLuint address
Definition: glext.h:6947
mrpt::comms::net::http_request
ERRORCODE_HTTP http_request(const string &http_method, const string &http_send_content, const string &url, std::vector< uint8_t > &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=nullptr, mrpt::system::TParameters< string > *extra_headers=nullptr, mrpt::system::TParameters< string > *out_headers=nullptr, int timeout_ms=1000)
Generic function for HTTP GET & POST methods.
Definition: net_utils.cpp:69
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
TParameters.h
mrpt::comms::net::DNS_resolve_async
bool 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:404
mrpt::comms::net::erBadURL
@ erBadURL
Definition: net_utils.h:34
mrpt::comms::net::erOk
@ erOk
Definition: net_utils.h:33
mrpt::comms::net::ERRORCODE_HTTP
ERRORCODE_HTTP
Possible returns from a HTTP request.
Definition: net_utils.h:31
mrpt::system::TParameters
For usage when passing a dynamic number of (numeric) arguments to a function, by name.
Definition: TParameters.h:56
url
string url
Definition: vision_stereo_rectify/test.cpp:18
comms
Definition: CInterfaceFTDI_WIN.cpp:19
mrpt::comms::net::erCouldntConnect
@ erCouldntConnect
Definition: net_utils.h:35
mrpt::comms::net::getLastSocketErrorStr
std::string getLastSocketErrorStr()
Returns a description of the last Sockets error.
Definition: net_utils.cpp:480
mrpt::comms::net::http_get
ERRORCODE_HTTP http_get(const string &url, std::vector< uint8_t > &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=nullptr, mrpt::system::TParameters< string > *extra_headers=nullptr, mrpt::system::TParameters< string > *out_headers=nullptr, int timeout_ms=1000)
Perform an HTTP GET operation (version for retrieving the data as a std::vector<uint8_t>)
Definition: net_utils.cpp:386
mrpt::comms::net::Ping
bool Ping(const std::string &address, const int max_attempts, std::string *output_str=NULL)
Ping an IP address.
Definition: net_utils.cpp:498
mrpt::comms::net::erNotFound
@ erNotFound
Definition: net_utils.h:36
string
GLsizei const GLchar ** string
Definition: glext.h:4101



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST