Example #1
0
bool doRequest(Poco::Net::HTTPClientSession & session, Poco::Net::HTTPRequest & request, Poco::Net::HTTPResponse & response)
{
	session.sendRequest(request);
	std::istream& rs = session.receiveResponse(response);
	std::cout << response.getStatus() << " " << response.getReason() << std::endl;
	if (response.getStatus() != Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED)
	{
		//std::ofstream ofs("Poco_banner.jpg", std::fstream::binary);
		//StreamCopier::copyStream(rs, ofs);
		// Print to standard output
		cout << "RECEIVED:" << endl;
		std::copy(std::istream_iterator<char>(rs), std::istream_iterator<char>(), std::ostream_iterator<char>(std::cout) );
		cout << endl;
		return true;
	}
	else
	{
		//it went wrong ?
		return false;
	}
}
Example #2
0
bool doRequest(Poco::Net::HTTPClientSession & session, string requestBody, Poco::Net::HTTPRequest & request, Poco::Net::HTTPResponse & response)
{
	session.setKeepAlive(true);
	request.setKeepAlive(true);
	request.setContentType("application/x-www-form-urlencoded");
	request.setContentLength(requestBody.length());

	session.sendRequest(request) << requestBody;
	std::istream& rs = session.receiveResponse(response);
	std::cout << response.getStatus() << " " << response.getReason() << std::endl;
	if (response.getStatus() != Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED)
	{
		
		//std::ofstream ofs("Poco_banner.jpg", std::fstream::binary);
		//StreamCopier::copyStream(rs, ofs);
		// Print to standard output
		cout << "RECEIVED:" << endl;
		//std::copy(std::istream_iterator<char>(rs), std::istream_iterator<char>(), std::ostream_iterator<char>(std::cout));
		string received = "";
		string temp;
		//rec << rs.rdbuf();
		
		while (std::getline(rs, temp))
		{
			received += temp + "\n";
		}

		cout << received << endl;
		return true;
	}
	else
	{
		//it went wrong ?
		return false;
	}
}