MRPT  2.0.4
comms_http_client/test.cpp
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| https://www.mrpt.org/ |
| |
| Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
| See: https://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */
/** \example comms_http_client/test.cpp */
//! [example-http-get]
#include <iostream>
using namespace mrpt;
using namespace mrpt::comms;
using namespace mrpt::comms::net;
using namespace std;
string url = "http://www.google.es/";
{
string content;
string errmsg;
cout << "Retrieving " << url << "..." << endl;
url, content, errmsg, 80, "", "", nullptr, nullptr, &out_headers);
if (ret != net::erOk)
{
cout << " Error: " << errmsg << endl;
return;
}
string typ = out_headers.has("Content-Type") ? out_headers["Content-Type"]
: string("???");
cout << "Ok: " << content.size() << " bytes of type: " << typ << endl;
// cout << content << endl;
}
//! [example-http-get]
int main(int argc, char** argv)
{
try
{
if (argc > 1) url = string(argv[1]);
return 0;
}
catch (const std::exception& e)
{
std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
return -1;
}
}
mrpt::system::TParameters::has
bool has(const std::string &s) const
Definition: TParameters.h:69
exceptions.h
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: BaseAppDataSource.h:15
Test_HTTP_get
void Test_HTTP_get()
Definition: vision_stereo_rectify/test.cpp:25
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:54
url
string url
Definition: vision_stereo_rectify/test.cpp:23
argv
const char * argv[]
Definition: RawlogGrabberApp_unittest.cpp:50
net_utils.h
argc
const int argc
Definition: RawlogGrabberApp_unittest.cpp:51
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::exception_to_str
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
mrpt::comms::net
A set of useful routines for networking.
Definition: net_utils.h:23



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Fri Jul 17 08:43:33 UTC 2020