Created
August 1, 2019 05:53
-
-
Save Mandar-Shinde/b774aee0d65cb7929961281e981d3259 to your computer and use it in GitHub Desktop.
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
#include "Poco/Net/HTTPClientSession.h" | |
#include "Poco/Net/HTTPRequest.h" | |
#include "Poco/Net/HTTPResponse.h" | |
#include "Poco/Base64Encoder.h" | |
#include "Poco/Net/HTMLForm.h" | |
#include "Poco/Net/StringPartSource.h" | |
#include "Poco/StreamCopier.h" | |
#include "Poco/Buffer.h" | |
Poco::Net::HTTPClientSession s("fileserver.com",80); | |
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/upload.php"); | |
// Create a new HTMLForm to submit to and add some basic string data | |
Poco::Net::HTMLForm form; | |
form.add("token", "APP_TOKEN"); | |
form.add("username", "USERNAME"); | |
form.add("password", "PASSWORD_HASH"); | |
// Take a screenshot of the current openFrameworks app | |
ofImage screenImg; | |
screenImg.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR); | |
screenImg.grabScreen(0, 0, ofGetWidth(), ofGetHeight()); | |
ofBuffer buffer; | |
ofSaveImage(screenImg.getPixelsRef(), buffer, OF_IMAGE_FORMAT_JPEG, OF_IMAGE_QUALITY_BEST); | |
// Convert the binary image data to string using base64 encoding | |
stringstream ss; | |
Poco::Base64Encoder b64enc(ss); | |
b64enc << buffer; | |
// Add the encodeded image data to the form | |
form.add("image", ss.str()); | |
// Fill out the request object and write to output stream | |
form.prepareSubmit(request); | |
ostream& send = s.sendRequest(request); | |
form.write(send); | |
// Get and print out the response from the server | |
Poco::Net::HTTPResponse response; | |
istream& res = s.receiveResponse(response); | |
ostringstream stream; | |
Poco::StreamCopier::copyStream(res, stream); | |
cout << stream.str() << endl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment