Created
April 14, 2013 13:33
-
-
Save anonymous/5382750 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/StreamCopier.h> | |
#include <Poco/Path.h> | |
#include <Poco/URI.h> | |
#include <Poco/Exception.h> | |
#include <iostream> | |
#include <string> | |
using namespace Poco::Net; | |
using namespace Poco; | |
using namespace std; | |
int main(int argc, char **argv) | |
{ | |
HTTPClientSession session("stkaddons.net"); //create session with stkaddons | |
session.setKeepAlive(true); | |
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, "http://stkaddons.net/client-user.php?action=connect&user=testingnw&password=p@ssword", HTTPMessage::HTTP_1_1); | |
req.setContentType("application/x-www-form-urlencoded"); | |
req.setKeepAlive(true); // notice setKeepAlive is also called on session (above) | |
std::string reqBody("This is an authentication request"); | |
req.setContentLength( reqBody.length() ); | |
std::ostream& myOStream = session.sendRequest(req); // sends request, returns open stream | |
myOStream << reqBody; // sends the body | |
req.write(std::cout); | |
Poco::Net::HTTPResponse res; | |
std::istream& iStr = session.receiveResponse(res); // get the response from server | |
std::cerr << iStr.rdbuf()<<std::endl; // dump server response so you can view it | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment