Created
February 1, 2014 16:55
-
-
Save sturmer/8755127 to your computer and use it in GitHub Desktop.
Rotten Tomatoes API access with POCO libraries
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
// Access Rotten Tomatoes API | |
#include "Poco/Net/HTTPClientSession.h" | |
#include "Poco/Net/HTTPRequest.h" | |
#include "Poco/Net/HTTPResponse.h" | |
#include "Poco/Net/HTMLForm.h" | |
#include "Poco/StreamCopier.h" | |
#include "Poco/Exception.h" | |
#include <string> | |
#include <fstream> | |
#include <iostream> | |
using std::string; | |
using std::cout; | |
using std::cerr; | |
using std::endl; | |
using std::istream; | |
using std::ofstream; | |
using namespace Poco::Net; | |
int main() | |
{ | |
try { | |
HTTPRequest movierequest(HTTPRequest::HTTP_GET, "/api/public/v1.0/movies.json", HTTPMessage::HTTP_1_1); | |
HTMLForm form; | |
form.add("apikey", "<your_API_key>"); // use your API key here | |
form.add("page", "1"); | |
form.add("page_limit", "10"); | |
form.add("q", "Toy+Story"); | |
form.prepareSubmit(movierequest); | |
HTTPClientSession s("api.rottentomatoes.com"); | |
s.sendRequest(movierequest); | |
HTTPResponse resp; | |
istream& response_stream = s.receiveResponse(resp); | |
cout << resp.getStatus() << " " << resp.getReason() << endl; | |
ofstream result("toystory.txt"); | |
Poco::StreamCopier::copyStream(response_stream, result); | |
} catch (Poco::Exception &ex) { | |
cerr << "Exception: " << ex.className() << " -- " << ex.displayText() << endl; | |
return -1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment