diff options
Diffstat (limited to 'test_poco_http.c')
| -rw-r--r-- | test_poco_http.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test_poco_http.c b/test_poco_http.c new file mode 100644 index 0000000..e4c95a5 --- /dev/null +++ b/test_poco_http.c @@ -0,0 +1,65 @@ +#include "Poco/Net/HTTPClientSession.h" +#include "Poco/Net/HTTPRequest.h" +#include "Poco/Net/HTTPResponse.h" +#include "Poco/StreamCopier.h" +#include "Poco/Path.h" +#include "Poco/URI.h" +#include "Poco/Exception.h" +#include <iostream> +#include <string> + +#include "Poco/Net/HTTPSClientSession.h" +#include "Poco/Net/InvalidCertificateHandler.h" +#include "Poco/Net/AcceptCertificateHandler.h" +#include "Poco/Net/SSLManager.h" + +using namespace Poco::Net; +using namespace Poco; +using namespace std; + +int main(int argc, char **argv) +{ + if (argc != 2) + { + cout << "Usage: " << argv[0] << " <uri>" << endl; + cout << " fetches the resource identified by <uri> and print it" << endl; + return -1; + } + + try + { + // prepare session + URI uri(argv[1]); + + + Poco::Net::Context::Ptr context =new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", + "","",Poco::Net::Context::VERIFY_RELAXED, + 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); + Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> pAcceptCertHandler = new Poco::Net::AcceptCertificateHandler(true); + Poco::Net::SSLManager::instance().initializeClient(NULL, pAcceptCertHandler, context); + + HTTPSClientSession session(uri.getHost(), uri.getPort(),context); + // prepare path + string path(uri.getPathAndQuery()); + if (path.empty()) path = "/"; + + // send request + HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); + session.sendRequest(req); + + // get response + HTTPResponse res; + cout << res.getStatus() << " " << res.getReason() << endl; + + // print response + istream &is = session.receiveResponse(res); + StreamCopier::copyStream(is, cout); + } + catch (Exception &ex) + { + cerr << ex.displayText() << endl; + return -1; + } + + return 0; +}
\ No newline at end of file |
