summaryrefslogtreecommitdiff
path: root/test_poco_http.c
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-03-06 16:09:25 +0000
committerTim Redfern <tim@eclectronics.org>2014-03-06 16:09:25 +0000
commit3d0177e837863f0e6143c269ee37266b59e69ab1 (patch)
tree408170167edc675350cbe1ebfc36adb97ede2ce8 /test_poco_http.c
parent3726e496813e556e88baf5dc8acabe290a1a66f4 (diff)
SSL OK
Diffstat (limited to 'test_poco_http.c')
-rw-r--r--test_poco_http.c65
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