Пример #1
0
bool myClientInteractor::sendRequest(Poco::Net::HTTPClientSession& session, Poco::Net::HTTPRequest& request, Poco::Net::HTTPResponse& response){
	//tracker->stringify(std::cout, 0);
	try{
	str.clear();
	tracker->stringify(str, 0);
	str >> json;
	//std::cout << "Sending: " << json << std::endl;
	std::cout << response.getStatus() << " " << response.getReason() << std::endl;
	
	if (response.getStatus() != Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED)
	{
		std::ostream& os = session.sendRequest(request);
		//std::cout << "HERE NO PROBLEMS!!" << std::endl;	
		os << json;


		return true;
	}
	else
	{
		//std::cout << "NULL!!!!" << std::endl;
		Poco::NullOutputStream null;
		//StreamCopier::copyStream(rs, null);
		return false;
	}
	
	}catch(Exception& exc)
	{
		std::cerr << exc.displayText() << std::endl;
		return 1;
	}
}
Пример #2
0
Poco::Net::HTTPClientSession* doHTTPIO(const Poco::URI& uri,
    const std::string& type, std::vector<HTTPHeader>* params) {
  Poco::Net::HTTPClientSession *session = new HTTPClientSession(uri.getHost(),
      uri.getPort());
  Poco::Net::HTTPRequest request(type, uri.getPathAndQuery());

  //Add params
  if (params != nullptr && params->size() > 0) {
    vector<HTTPHeader>::iterator it = params->begin();
    while (it != params->end()) {
      string key = it->getKey();
      string value = it->getValue();
      request.add(key, value);
      it++;
    }
  }
  session->sendRequest(request);
  return session;
}
Пример #3
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;
	}
}
Пример #4
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;
	}
}