MRPT  2.0.2
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;
}
}



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020