-
-
Save pcannon67/d0ebc218a6ca056b9547d58f0c566d4e to your computer and use it in GitHub Desktop.
A poco http example
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
Poco::JSON::Object obj; | |
obj.set("name", "blah"); | |
obj.set("language", "english"); | |
Poco::URI uri("http://the-uri-you-want-to-request-from"); | |
std::string path(uri.getPathAndQuery()); | |
if (path.empty()) path = "/"; | |
HTTPClientSession session(uri.getHost(), uri.getPort()); | |
HTTPRequest request(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1); | |
HTTPResponse response; | |
request.setContentType("application/json"); | |
std::stringstream ss; | |
obj.stringify(ss); | |
request.setContentLength(ss.str().size()); | |
std::ostream& o = session.sendRequest(request); | |
obj.stringify(o); | |
// this line is where you get your response | |
std::istream& s = session.receiveResponse(response); | |
Poco::JSON::Parser parser; | |
Poco::JSON::Object::Ptr ret = parser.parse(s).extract<Poco::JSON::Object::Ptr>(); | |
// (*ret) will contain all the members in a json structure returned | |
if ((*ret).get("success") != true) { | |
std::cout << "Failed to upload: " << (*ret).get("message").toString(); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment