Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
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 
10 #include <mrpt/comms/net_utils.h>
11 #include <iostream>
12 
13 using namespace mrpt;
14 using namespace mrpt::comms;
15 using namespace mrpt::comms::net;
16 using namespace std;
17 
18 string url = "http://www.google.es/";
19 
20 /* ------------------------------------------------------------------------
21  Test: HTTP get
22  ------------------------------------------------------------------------ */
23 void Test_HTTP_get()
24 {
25  string content;
26  string errmsg;
28 
29  cout << "Retrieving " << url << "..." << endl;
30 
31  // CClientTCPSocket::DNS_LOOKUP_TIMEOUT_MS = 5000;
32 
34  url, content, errmsg, 80, "", "", nullptr, nullptr, &out_headers);
35 
36  if (ret != net::erOk)
37  {
38  cout << " Error: " << errmsg << endl;
39  return;
40  }
41 
42  string typ = out_headers.has("Content-Type") ? out_headers["Content-Type"]
43  : string("???");
44 
45  cout << "Ok: " << content.size() << " bytes of type: " << typ << endl;
46  // cout << content << endl;
47 }
48 
49 // ------------------------------------------------------
50 // MAIN
51 // ------------------------------------------------------
52 int main(int argc, char** argv)
53 {
54  try
55  {
56  if (argc > 1) url = string(argv[1]);
57 
58  Test_HTTP_get();
59 
60  return 0;
61  }
62  catch (std::exception& e)
63  {
64  std::cout << "Exception: " << e.what() << std::endl;
65  return -1;
66  }
67  catch (...)
68  {
69  printf("Untyped exception!");
70  return -1;
71  }
72 }
mrpt::system::TParameters::has
bool has(const std::string &s) const
Definition: TParameters.h:85
mrpt::comms
Serial and networking devices and utilities.
Definition: CClientTCPSocket.h:21
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
Test_HTTP_get
void Test_HTTP_get()
Definition: vision_stereo_rectify/test.cpp:23
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
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
net_utils.h
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
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::comms::net
A set of useful routines for networking.
Definition: net_utils.h:23



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