当前位置: 首页>>代码示例>>C++>>正文


C++ HTTPServerResponse::send方法代码示例

本文整理汇总了C++中poco::net::HTTPServerResponse::send方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerResponse::send方法的具体用法?C++ HTTPServerResponse::send怎么用?C++ HTTPServerResponse::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在poco::net::HTTPServerResponse的用法示例。


在下文中一共展示了HTTPServerResponse::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleRequest

void GenericFileHandler::handleRequest(Poco::Net::HTTPServerRequest & req, Poco::Net::HTTPServerResponse & resp) {

	std::ifstream file;

	try {
		file.open(fileName.c_str(), std::ifstream::in);
	} catch (...) {
	}

	if (!file.is_open()) {
		resp.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);
		resp.send();
		return;
	}

	std::string wsdl;
	while (!file.eof()) {
		std::string tmp;
		std::getline(file, tmp);
		wsdl += tmp;
	}
	file.close();

	resp.setStatus(Poco::Net::HTTPResponse::HTTP_OK);
	resp.setContentType("application/xml");
	resp.setChunkedTransferEncoding(false);
	resp.setContentLength(wsdl.length());

	std::ostream & out = resp.send();
	out << wsdl << std::flush;
}
开发者ID:surgitaix,项目名称:osclib,代码行数:31,代码来源:GenericFileHandler.cpp

示例2: handleRequest

    void handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response)
    {
        if(request.getURI()=="/command") {
            EachInputValue(request, [&](const char *id, const char *command){
                wdmEventData tmp = {std::atoi(id), command};
                wdmSystem::getInstance()->addEvent(tmp);
            });
            response.setContentType("text/plain");
            response.setContentLength(2);
            std::ostream &ostr = response.send();
            ostr.write("ok", 3);
        }
        else if(request.getURI()=="/data") {
            std::vector<wdmID> nodes;
            nodes.push_back(_wdmGetRootNode()->getID());
            EachNodeValue(request, [&](const char *id){
                nodes.push_back(std::atoi(id));
            });

            wdmString json;
            wdmJSONRequest request = {false, false, &json, nodes.empty() ? NULL : &nodes[0], (uint32_t)nodes.size()};
            wdmSystem::getInstance()->requestJSON(request);
            while(!request.done) { Poco::Thread::sleep(2); }
            if(request.canceled) { json="[]"; }

            response.setContentType("application/json");
            response.setContentLength(json.size());
            std::ostream &ostr = response.send();
            ostr.write(&json[0], json.size());
        }
    }
开发者ID:ezhangle,项目名称:WebDebugMenu,代码行数:31,代码来源:WebDebugMenu.cpp

示例3: handleRequest

void RESTHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
                                Poco::Net::HTTPServerResponse &response) {
    if (verbose) {
        std::clog << "HTTP request " << request.getURI() << std::endl;
        std::clog << "Context id: " << client.context_id() << std::endl;
    }
    zmqpp::message msg, reply;
    /// Connect to broker if not connected
    client.connect(broker);
    Poco::URI url(request.getURI());
    Poco::Net::HTMLForm form(request);
    /// Filter by black list
    if (black_list.find(url.getPath()) != black_list.end()) {
        return error_black_list(response);
    }
    if (!build_message(request, form, url, msg)) {
        return error_parse(response);
    }
    if (!client.send_request(msg, reply, (form.has("timeout") ? std::stoi(form.get("timeout")) : timeout))) {
        return error_timeout(response);
    }
    /// Render response
    response.setStatus(Poco::Net::HTTPServerResponse::HTTPStatus::HTTP_OK);
    if (form.get("type", "json") == "json") {
        /// JSON in single line (FastWriter)
        std::string jsonp_callback = form.get("jsonp", form.get("callback", ""));
        Json::Value packet(Json::ValueType::arrayValue);
        response.setContentType("application/json");
        std::ostream &out = response.send();
        if (!jsonp_callback.empty())
            out << jsonp_callback << "(";
        for (size_t part = 0; part < reply.parts(); ++part)
            packet.append(reply.get(part));
        auto txt = writer.write(packet);
        if (txt[txt.size() - 1] == '\n') // Cheat for EOL in serialization
            txt = txt.substr(0, txt.size() - 1);
        out << txt << (!jsonp_callback.empty() ? ")" : "") << std::flush;
    } else {
        /// Plain text wihtout delimiters
        response.setContentType("text/plain");
        std::ostream &out = response.send();
        for (size_t part = 0; part < reply.parts(); ++part)
            out.write((char *) reply.raw_data(part), reply.size(part));
        out.flush();
    }


}
开发者ID:ruslanec,项目名称:waha,代码行数:48,代码来源:http.cpp

示例4: streamFile

		static void streamFile(Poco::Net::HTTPServerResponse & response, std::string file, std::string mime) {
			response.setContentType(mime);
			response.setChunkedTransferEncoding(true);
			std::ostream & o = response.send();
			std::ifstream docf(file.c_str());
			Poco::StreamCopier::copyStream(docf, o);
		}
开发者ID:hadzim,项目名称:bb,代码行数:7,代码来源:JsonServices.cpp

示例5: operator

 void ShowDevices::operator()(const PlaceHolders &&, ServerRequest &request,
                              Poco::Net::HTTPServerResponse &response) {
     response.setStatus(Poco::Net::HTTPResponse::HTTP_OK);
     BOOST_LOG_TRIVIAL(info) << "ShowDevices";
     const auto &producer = MediaTypeProducerFactory::getMediaType(request.getContentType());
     producer.produce(response.send(), ZDevicesPT(singletons.getZDevices()));
 }
开发者ID:paoloach,项目名称:zdomus,代码行数:7,代码来源:ShowDevices.cpp

示例6: handleRequest

void TimeHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
    response.setChunkedTransferEncoding(true);
    response.setContentType("text/html");

    Poco::Net::HTMLForm form(request, request.stream());
    std::ostream& responseStream = response.send();
    responseStream << "";
    responseStream << "\n";
    responseStream << "";
    responseStream << "\n";
    responseStream << "\n";
    responseStream << "";
#line 6 "/ws/poco-1.3/PageCompiler/samples/HTTPTimeServer/src/TimeHandler.cpsp"

    Poco::DateTime now;
    std::string dt(Poco::DateTimeFormatter::format(now, "%W, %e %b %y %H:%M:%S %Z"));
    responseStream << "\n";
    responseStream << "<html>\n";
    responseStream << "<head>\n";
    responseStream << "<title>HTTPTimeServer powered by POCO C++ Libraries and PageCompiler</title>\n";
    responseStream << "<meta http-equiv=\"refresh\" content=\"1\">\n";
    responseStream << "</head>\n";
    responseStream << "<body>\n";
    responseStream << "<p style=\"text-align: center; font-size: 48px;\">";
#line 16 "/ws/poco-1.3/PageCompiler/samples/HTTPTimeServer/src/TimeHandler.cpsp"
    responseStream << ( dt );
    responseStream << "</p>\n";
    responseStream << "</body>\n";
    responseStream << "</html>\n";
    responseStream << "";
}
开发者ID:as2120,项目名称:ZPoco,代码行数:32,代码来源:TimeHandler.cpp

示例7: handleRequest

	void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) 
	{ 
		response.setContentType("text/xml");
		std::ostream& ostr = response.send();
		redis r;
		r.arg("zrange");
		r.arg("history");
		r.arg("0");
		r.arg("-1");
		std::list<std::string> result;
		r.exec_array(result);

		std::string rss;
		rss =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<rss version=\"2.0\">"
"  <channel>"
"    <title>rss</title>"
"    <link>http://localhost/</link>"
"    <description>merge rss feeds</description>";

		for (std::list<std::string>::reverse_iterator it = result.rbegin(), end = result.rend(); it != end; ++it)
		{
			r.arg("hget");
			r.arg("items");
			r.arg(*it);
			rss += r.exec_string().second;
		}
		rss += "</channel></rss>";
		ostr << rss << std::flush;
	} 
开发者ID:Arcen,项目名称:rssd,代码行数:31,代码来源:main.cpp

示例8: generateResponse

void GetHighScoreDeleteForm::generateResponse(Poco::Net::HTTPServerRequest& inRequest, Poco::Net::HTTPServerResponse& outResponse)
{
    std::string body;
    ReadEntireFile("html/delete.html", body);
    outResponse.setContentLength(body.size());
    outResponse.send() << body;
}
开发者ID:boodjoom,项目名称:stacked-crooked,代码行数:7,代码来源:Config.cpp

示例9: handleRequest

void ConsoleRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
	try
	{
		std::string username;
		Poco::OSP::Web::WebSession::Ptr pSession;
		{
			Poco::OSP::ServiceRef::Ptr pWebSessionManagerRef = _pContext->registry().findByName(Poco::OSP::Web::WebSessionManager::SERVICE_NAME);
			if (pWebSessionManagerRef)
			{
				Poco::OSP::Web::WebSessionManager::Ptr pWebSessionManager = pWebSessionManagerRef->castedInstance<Poco::OSP::Web::WebSessionManager>();
				pSession = pWebSessionManager->find(_pContext->thisBundle()->properties().getString("websession.id"), request);
				username = pSession->getValue<std::string>("username", "");
			}
		}	
	
		if (!username.empty())
		{
			Poco::Net::WebSocket webSocket(request, response);
			_pContext->logger().information(Poco::format("Console WebSocket connection established with %s.", request.clientAddress().toString()));
			forwardMessages(webSocket);
		}
		else
		{
			response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED);
			response.setContentLength(0);
			response.send();
		}
	}
	catch (Poco::Net::WebSocketException& exc)
	{
		_pContext->logger().log(exc);
		switch (exc.code())
		{
		case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
			response.set("Sec-WebSocket-Version", Poco::Net::WebSocket::WEBSOCKET_VERSION);
			// fallthrough
		case Poco::Net::WebSocket::WS_ERR_NO_HANDSHAKE:
		case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
		case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
			response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
			response.setContentLength(0);
			response.send();
			break;
		}
	}
}
开发者ID:curiousTauseef,项目名称:macchina.io,代码行数:47,代码来源:ConsoleRequestHandler.cpp

示例10: handleRequest

        void FixedPathHandler::handleRequest(Poco::Net::HTTPServerRequest &, Poco::Net::HTTPServerResponse &response) {
            Poco::Net::MediaType mediaType("text", "plain");
            response.setContentType(mediaType);
            response.setStatus(Poco::Net::HTTPResponse::HTTP_OK);

            std::ostream &stream = response.send();
            stream << "value";
        }
开发者ID:paoloach,项目名称:zdomus,代码行数:8,代码来源:FixedPathHandler.cpp

示例11: handleRequest

	virtual void handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response)
	{
		if (request.getURI() == "/name")
		{
			response.setContentType("application/json");
			response.send() << " { \"hanwenfang\"} ";
		}
	}
开发者ID:HanWenfang,项目名称:Restful-Service-Backend,代码行数:8,代码来源:HelloWorld.cpp

示例12: process

	void process(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, const std::string& path, std::istream& resourceStream, Poco::OSP::Bundle::ConstPtr pBundle)
	{
		std::string content;
		Poco::StreamCopier::copyToString(resourceStream, content);
		std::string dateTime = Poco::DateTimeFormatter::format(Poco::DateTime(), Poco::DateTimeFormat::HTTP_FORMAT);
		Poco::replaceInPlace(content, std::string("$$DATETIME$$"), dateTime);
		response.setContentType("text/html");
		response.send() << content;
	}
开发者ID:curiousTauseef,项目名称:macchina.io,代码行数:9,代码来源:WebFilter.cpp

示例13:

void server::BasicHandler::handleRequest( Poco::Net::HTTPServerRequest & request,
					  Poco::Net::HTTPServerResponse & response) {
  std::cout << "Received Request!" << std::endl;

  response.setContentType("text/txt");
  response.setStatus(Poco::Net::HTTPResponse::HTTP_OK);
  std::ostream& os = response.send();
  os << "12345 this is all pretty weird" << std::endl;
}
开发者ID:julitopower,项目名称:POCOBasedHTTPServer,代码行数:9,代码来源:BasicHandler.cpp

示例14: DefaultRequestHandler

void DefaultRequestHandler(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
  response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_OK);
  response.setContentType(Poco::Net::MediaType("text/plain"));
  response.setKeepAlive(true);
  auto& os = response.send();

  os << "It Works! " << request.getURI() << std::flush;
}
开发者ID:elkvis,项目名称:PocoHttpRouter,代码行数:9,代码来源:HttpRouterTest.cpp

示例15: handleRequest

void ShowCaptchaPage::handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response)
{
	m_log->trace("ShowCaptchaPage::handleRequest from "+request.clientAddress().toString());

	std::map<std::string,QueryVar> queryvars;

	CreateQueryVarMap(request,queryvars);

	if(request.getVersion()==Poco::Net::HTTPRequest::HTTP_1_1)
	{
		response.setChunkedTransferEncoding(true);
	}

	std::string content="";
	if(queryvars.find("UUID")!=queryvars.end())
	{
		std::string uuid=(*queryvars.find("UUID")).second.GetData();
		SQLite3DB::Statement st=m_db->Prepare("SELECT MimeType,PuzzleData FROM tblIntroductionPuzzleRequests WHERE UUID=?;");
		st.Bind(0,uuid);
		st.Step();

		if(st.RowReturned())
		{
			std::string mime;
			std::string b64data;
			std::vector<unsigned char> data;

			st.ResultText(0,mime);
			st.ResultText(1,b64data);
			Base64::Decode(b64data,data);

			// mime type should be short and have a / in it - otherwise skip
			if(mime.size()<50 && mime.find('/')!=std::string::npos)
			{
				std::string fname(uuid);
				if(mime=="image/bmp")
				{
					fname+=".bmp";
				}
				else if(mime=="audio/x-wav")
				{
					fname+=".wav";
				}
				response.setContentType(mime);
				response.setContentLength(data.size());
				response.set("Content-Disposition","attachment; filename="+fname);
				content+=std::string(data.begin(),data.end());
			}
		}
	}

	std::ostream &ostr = response.send();
	ostr << content;
}
开发者ID:SeekingFor,项目名称:FMS,代码行数:54,代码来源:showcaptchapage.cpp


注:本文中的poco::net::HTTPServerResponse::send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。