Skip to content

Instantly share code, notes, and snippets.

Created April 14, 2013 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5382750 to your computer and use it in GitHub Desktop.
Save anonymous/5382750 to your computer and use it in GitHub Desktop.
#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