Created
March 24, 2021 16:08
-
-
Save xulman/23f08764fe76cc6b95d70bce36fc3788 to your computer and use it in GitHub Desktop.
C++ example code how to submit http comm using the Poco project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ more *.* | |
:::::::::::::: | |
CMakeLists.txt | |
:::::::::::::: | |
cmake_minimum_required (VERSION 3.5) | |
project (poco-VladoClientTest) | |
find_package (Poco REQUIRED Net) | |
add_executable (clientTest main.cpp) | |
target_link_libraries (clientTest Poco::Net) | |
:::::::::::::: | |
main.cpp | |
:::::::::::::: | |
#include <iostream> | |
#include <Poco/Net/HTTPClientSession.h> | |
#include <Poco/Net/HTTPRequest.h> | |
#include <Poco/Net/HTTPResponse.h> | |
#include <Poco/Net/NetException.h> | |
int main(int argc,char** argv) | |
{ | |
try { | |
using namespace Poco::Net; | |
HTTPClientSession session("www.seznam.cz",80); | |
std::cout << "is connected? " << session.connected() << "\n"; //not yet | |
HTTPRequest request(HTTPRequest::HTTP_GET, "/"); | |
session.sendRequest(request); | |
//or, std::ostream &postDataGoesHere = session.sendRequest(request); | |
std::cout << "is connected? " << session.connected() << "\n"; //already is | |
HTTPResponse response; | |
session.receiveResponse( response ); | |
std::cout << "got back: status = " << response.getStatus() << "\n"; | |
std::cout << "content starts:\n"; | |
response.write( std::cout ); | |
std::cout << "content ends:\n"; | |
} | |
catch (Poco::Net::NetException& e) { | |
std::cout << "Got exception: " << e.what() << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here's how to communicate to SimViewer: