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 /** \example comms_http_client/test.cpp */
11 
12 //! [example-http-get]
13 
14 #include <mrpt/comms/net_utils.h>
15 #include <iostream>
16 
17 using namespace mrpt;
18 using namespace mrpt::comms;
19 using namespace mrpt::comms::net;
20 using namespace std;
21 
22 string url = "http://www.google.es/";
23 
24 void Test_HTTP_get()
25 {
26  string content;
27  string errmsg;
29 
30  cout << "Retrieving " << url << "..." << endl;
31 
33  url, content, errmsg, 80, "", "", nullptr, nullptr, &out_headers);
34 
35  if (ret != net::erOk)
36  {
37  cout << " Error: " << errmsg << endl;
38  return;
39  }
40 
41  string typ = out_headers.has("Content-Type") ? out_headers["Content-Type"]
42  : string("???");
43 
44  cout << "Ok: " << content.size() << " bytes of type: " << typ << endl;
45  // cout << content << endl;
46 }
47 //! [example-http-get]
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 }
STL namespace.
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
void Test_HTTP_get()
ERRORCODE_HTTP
Possible returns from a HTTP request.
Definition: net_utils.h:31
bool has(const std::string &s) const
Definition: TParameters.h:83
GLsizei const GLchar ** string
Definition: glext.h:4101
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A set of useful routines for networking.
Definition: net_utils.h:23
Serial and networking devices and utilities.
For usage when passing a dynamic number of (numeric) arguments to a function, by name.
Definition: TParameters.h:54



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020