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


C++ HTTPServerResponse类代码示例

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


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

示例1: handleRequest

	void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
	{
		response.setChunkedTransferEncoding(true);
		response.setContentType(request.getContentType());
		std::ostream& ostr = response.send();
		Poco::StreamCopier::copyStream(request.stream(), ostr);
	}
开发者ID:,项目名称:,代码行数:7,代码来源:

示例2: handleRequest

	void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
	{
		Application& app = Application::instance();
		app.logger().information("Request from " + request.clientAddress().toString());

		SecureStreamSocket socket = static_cast<HTTPServerRequestImpl&>(request).socket();
		if (socket.havePeerCertificate())
		{
			X509Certificate cert = socket.peerCertificate();
			app.logger().information("Client certificate: " + cert.subjectName());
		}
		else
		{
			app.logger().information("No client certificate available.");
		}
		
		Timestamp now;
		std::string dt(DateTimeFormatter::format(now, _format));

		response.setChunkedTransferEncoding(true);
		response.setContentType("text/html");

		std::ostream& ostr = response.send();
		ostr << "<html><head><title>HTTPTimeServer powered by POCO C++ Libraries</title>";
		ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
		ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
		ostr << dt;
		ostr << "</p></body></html>";
	}
开发者ID:BrianHoldsworth,项目名称:Poco,代码行数:29,代码来源:HTTPSTimeServer.cpp

示例3:

void PageRequestHandler::handleRequest
(HTTPServerRequest& request, HTTPServerResponse& response)
{
    response.setChunkedTransferEncoding(true);
    response.setContentType("text/html");
    const char *message = "The quick brown fox jumps over the lazy dog.\n";
    for(int i {0}; i < 100; ++i)
    {
        response.sendBuffer(message, 44);
    }
}
开发者ID:oldoak,项目名称:sandbox,代码行数:11,代码来源:PageRequestHandler.C

示例4: handleRequest

void PageRequestHandler::handleRequest( HTTPServerRequest& request, 
                                        HTTPServerResponse& response ) 
{
    response.setChunkedTransferEncoding(true);
    response.setContentType("text/html");
    std::ostream& ostr = response.send();
    ostr<<"<html>";
    ostr<<"<body>";
    ostr<<"Stub (HTML) output - insert JavaScript HERE";
    ostr<<"</body>";
    ostr<<"</html>";
}
开发者ID:egustafson,项目名称:sandbox,代码行数:12,代码来源:PageRequestHandler.cpp

示例5: handleRequest

 virtual void handleRequest(HTTPServerRequest &req, HTTPServerResponse &resp){
   resp.setStatus(HTTPResponse::HTTP_OK);
   resp.setContentType("text/html");
   
   // Generate requested HTML file
   ostream& out = resp.send();
   out << "<h1>Hello world! This files name is " << req.getURI() << "</h1>"
       << "<p>Host: "           << req.getHost()   << "</p>"
       << "<p>Method: "         << req.getMethod() << "</p>";
   out.flush();
   
   cout << endl << "Client requested: =" << req.getURI() << endl;  
 }
开发者ID:ClaytonSmith,项目名称:CPP-HTTP-1.0-Server,代码行数:13,代码来源:server.cpp

示例6: isValidRequest

//------------------------------------------------------------------------------
bool ofxWebServerBaseRouteHandler::isValidRequest(const Settings& settings,
                                                  HTTPServerRequest& request,
                                                  HTTPServerResponse& response) {
    
    string sessionId = "";
    
    // extract cookie from request
    NameValueCollection cookies;
    request.getCookies(cookies);
    NameValueCollection::ConstIterator it = cookies.find(settings.sessionCookieName);
    if (it != cookies.end()) {
        sessionId = it->second;
    } else {
        sessionId = ofxWebServerSessionManager::generateSessionKey(request);
        HTTPCookie cookie(settings.sessionCookieName,sessionId);
        cookie.setPath("/");
        // set no age, so it expires @ end of session
        response.addCookie(cookie);
    }
    
    // TODO: update session manager
    
    URI uri(request.getURI());
    
    const string path = uri.getPath(); // just get the path

    if(settings.requireAuthentication) {
        if(request.hasCredentials()) {
            HTTPBasicCredentials credentials(request);
            const string& user = credentials.getUsername();
            const string& pwd = credentials.getPassword();
            
            if(settings.username == credentials.getUsername() &&
               settings.password == credentials.getPassword()) {
                // add an authentication cookie?
                return true;
            } else {
                response.setStatusAndReason(HTTPResponse::HTTP_UNAUTHORIZED);
                sendErrorResponse(response);
                return false;
            }
        } else {
            response.requireAuthentication(settings.realm);
            response.setContentLength(0);
            response.send();
            return false;
        }
    } else {
        return true;
    }
}
开发者ID:bakercp,项目名称:ofxWebServer,代码行数:52,代码来源:ofxWebServerBaseRouteHandler.cpp

示例7: handleRequest

//------------------------------------------------------------------------------
void ofxIpVideoServerRouteHandler::handleRequest(HTTPServerRequest& request,
                                                 HTTPServerResponse& response) {
    
    
    if(isValidRequest(settings.route,request,response)) {
        MediaType mediaType("multipart/x-mixed-replace");
        mediaType.setParameter("boundary", settings.boundary);

        string expires = DateTimeFormatter::format(Timestamp(0), // the beginning of time
                                                   DateTimeFormat::HTTP_FORMAT);
        
        response.set("Cache-control","no-cache");
        response.setContentType(mediaType);
        response.set("Expires",expires);
        response.set("Pragma","no-cache");
        
        std::ostream& ostr = response.send(); // get output stream

        bool stopStreaming = false;
        
        while(ostr.good() && !stopStreaming) {
            if(!queue.empty()) {
                ofxIpVideoServerFramePtr frame = queue.pop();
                    if(frame != NULL) {
                        ofBuffer* buffer = &frame.get()->buffer;
                        ostr << settings.boundary;
                        ostr << "\r\n";
                        ostr << "Content-Type: image/jpeg";
                        ostr << "\r\n";
                        ostr << "Content-Length: " << ofToString(buffer->size());
                        ostr << "\r\n";
                        ostr << "\r\n";
                        ostr << *buffer;
                    } else {
                        ofLogVerbose("ofxIpVideoServerRouteHandler::handleRequest") << "Null buffer.";
                    }
                } else {
                    ofLogVerbose("ofxIpVideoServerRouteHandler::handleRequest") << "Queue empty.";
                }
            
            Thread::sleep(50);
        }
        
        queue.setActive(false); // a desperate move 
        
        ofLogNotice("ofxIpVideoServerRouteHandler::handleRequest") << "Client disconneted.";
        
        //sendErrorResponse(response);
    }
}
开发者ID:bakercp,项目名称:ofxIpVideoServer,代码行数:51,代码来源:ofxIpVideoServerRouteHandler.cpp

示例8: handleRequest

	void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
	{
		Timestamp now;
		std::string dt(DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT));

		response.setChunkedTransferEncoding(true);
		response.setContentType("text/html");

		std::ostream& ostr = response.send();
		ostr << "<html><head><title>TimeServer powered by POCO ApacheConnector</title>";
		ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
		ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
		ostr << dt;
		ostr << "</p></body></html>";
	}
开发者ID:Blonder,项目名称:poco,代码行数:15,代码来源:TimeServer.cpp

示例9: handleRequest

//------------------------------------------------------------------------------
void ofxWebServerUploadRouteHandler::handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) {
    if(isValidRequest(settings.route, request, response)) {
        HTMLForm form(request, request.stream(), *this);
        
        if(!settings.uploadRedirect.empty()) {
            response.redirect(settings.uploadRedirect);
        } else {
            response.setStatusAndReason(HTTPResponse::HTTP_OK);
            response.setContentLength(0);
            response.send();
        }
    } else {
        return; // isValidRequest took care of the response
    }
}
开发者ID:bakercp,项目名称:ofxWebServer,代码行数:16,代码来源:ofxWebServerUploadRouteHandler.cpp

示例10: handleRequest

 void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
 {
     Application& app = Application::instance();
     try
     {
         WebSocket ws(request, response);
         XDUTxtSetText(ID_CURRENT_STATUS, Convert::toQXStringRef(L"Выполнено подключение к плагину. Чтобы начать интерпретацию - кликните по соотвествующей кнопке плагина Вашего браузера."));
         char buffer[MAX_BUFFER_SIZE];
         int flags=0;
         int n=1;
         do
         {
             ZeroMemory(buffer, MAX_BUFFER_SIZE);
             n = ws.receiveFrame(buffer, sizeof(buffer), flags);
             wstring message = Convert::toUnicodeString(buffer);
             if (message == L"plugin-version") {
                 //Следующее сообщение передаст данные о плагине
                 n = ws.receiveBytes(buffer, sizeof(buffer), flags);
                 XDUTxtSetText(ID_BROWSER_PLUGIN_VERSION, Convert::toQXStringRef(Convert::toUnicodeString(buffer)));
             }
             if (message == L"exportSettings") {
                 n = ws.receiveBytes(buffer, sizeof(buffer), flags);
                 ImportSettings::globalSettings=Convert::jsonToSettings(Convert::toUnicodeString(buffer));
             }
             if (message == L"start-export") {
                 WebCore::getInstance().setSocket(&ws);
                 WebCore::startExport = true;
                 while (WebCore::startExport == true);
             }
         } while (n > 0);
     }
     catch (WebSocketException& exc)
     {
         switch (exc.code())
         {
         case WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
             response.set("Sec-WebSocket-Version", WebSocket::WEBSOCKET_VERSION);
         // fallthrough
         case WebSocket::WS_ERR_NO_HANDSHAKE:
         case WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
         case WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
             response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
             response.setContentLength(0);
             response.send();
             break;
         }
     }
 }
开发者ID:lenchis001,项目名称:HTMLExporter,代码行数:48,代码来源:WebCore.cpp

示例11: sendErrorResponse

void ofxWebServerBaseRouteHandler::sendErrorResponse(HTTPServerResponse& response) {
    // we will assume that the sender has set the status and
    // reason appropriately before calling the sendErrorResponse()
    
    HTTPResponse::HTTPStatus status = response.getStatus();
    string reason = response.getReason();
    response.setChunkedTransferEncoding(true);
    response.setContentType("text/html");
    std::ostream& ostr = response.send(); // get output stream
    ostr << "<html>";
    ostr << "<head><title>" << status << "-" << reason << "</title></head>";
    ostr << "<body>";
    ostr << "<h1>" << status << "-" << reason << "</h1>";
    ostr << "</body>";
    ostr << "<html>";
}
开发者ID:bakercp,项目名称:ofxWebServer,代码行数:16,代码来源:ofxWebServerBaseRouteHandler.cpp

示例12: handleRequest

	void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
	{
		Application& app = Application::instance();
		try
		{
			WebSocket ws(request, response);
			app.logger().information("WebSocket connection established.");
			char buffer[BUFF_LEN];
			int flags;
			int n;
			do
			{	
				int recvLen = 0;
				while (recvLen < BUFF_LEN) {
					n = ws.receiveFrame(buffer, BUFF_LEN - recvLen, flags);
					recvLen += n;
				}
				
				app.logger().information(Poco::format("Frame received (length=%d, flags=0x%x).", n, unsigned(flags)));
				
				String resp ("aaaaaaaaaa");
				
				ws.sendFrame(resp.getCStr(), resp.getLength(), flags);
			}
			while (n > 0 || (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
			app.logger().information("WebSocket connection closed.");
		}
		catch (WebSocketException& exc)
		{
			app.logger().log(exc);
			switch (exc.code())
			{
				case WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
					response.set("Sec-WebSocket-Version", WebSocket::WEBSOCKET_VERSION);
					// fallthrough
				case WebSocket::WS_ERR_NO_HANDSHAKE:
				case WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
				case WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
					response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
					response.setContentLength(0);
					response.send();
					break;
			}
		}
	}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:45,代码来源:WebSocketServer.cpp

示例13: handleRequest

	void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
	{
		Application& app = Application::instance();
		app.logger().information("Request from " + request.clientAddress().toString());

		Timestamp now;
		std::string dt(DateTimeFormatter::format(now, _format));

		response.setChunkedTransferEncoding(true);
		response.setContentType("text/html");

		std::ostream& ostr = response.send();
		ostr << "<html><head><title>HTTPTimeServer powered by POCO C++ Libraries</title>";
		ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
		ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
		ostr << dt;
		ostr << "</p></body></html>";
	}
开发者ID:Alcibiades586,项目名称:roadrunner,代码行数:18,代码来源:HTTPTimeServer.cpp

示例14: handleRequest

	void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
	{
		response.setChunkedTransferEncoding(true);
		response.setContentType("text/html");
		std::ostream& ostr = response.send();
		ostr << "<html>";
		ostr << "<head>";
		ostr << "<title>WebSocketServer</title>";
		ostr << "<script type=\"text/javascript\">";
		ostr << "function WebSocketTest()";
		ostr << "{";
		ostr << "  if (\"WebSocket\" in window)";
		ostr << "  {";
		ostr << "    var ws = new WebSocket(\"ws://" << request.serverAddress().toString() << "/ws\");";
		ostr << "    ws.onopen = function()";
		ostr << "      {";
		ostr << "        ws.send(\"Hello, world!\");";
		ostr << "      };";
		ostr << "    ws.onmessage = function(evt)";
		ostr << "      { ";
		ostr << "        var msg = evt.data;";
		ostr << "        alert(\"Message received: \" + msg);";
		ostr << "        ws.close();";
		ostr << "      };";
		ostr << "    ws.onclose = function()";
		ostr << "      { ";
		ostr << "        alert(\"WebSocket closed.\");";
		ostr << "      };";
		ostr << "  }";
		ostr << "  else";
		ostr << "  {";
		ostr << "     alert(\"This browser does not support WebSockets.\");";
		ostr << "  }";
		ostr << "}";
		ostr << "</script>";
		ostr << "</head>";
		ostr << "<body>";
		ostr << "  <h1>WebSocket Server</h1>";
		ostr << "  <p><a href=\"javascript:WebSocketTest()\">Run WebSocket Script</a></p>";
		ostr << "</body>";
		ostr << "</html>";
	}
开发者ID:ZhaoboMeng,项目名称:k-line-print,代码行数:42,代码来源:WebSocketServer.cpp

示例15: handleRequest

    void handleRequest(HTTPServerRequest& request,
                       HTTPServerResponse& response)
    {
        StringTokenizer tok("/");
        StringVector tized;
        tok.tokenize(request.getURI(), tized);            
        if ( tized.size() == 4 )
        {
            int z = as<int>(tized[1], 0);
            int x = as<int>(tized[2], 0);
            unsigned int y = as<int>(osgDB::getNameLessExtension(tized[3]),0);
            std::string ext = osgDB::getFileExtension(tized[3]);

            OE_DEBUG << "z=" << z << std::endl;
            OE_DEBUG << "x=" << x << std::endl;
            OE_DEBUG << "y=" << y << std::endl;              
            OE_DEBUG << "ext=" << ext << std::endl;

            response.setChunkedTransferEncoding(true);

            osg::ref_ptr< osg::Image > image = _server->getTile(z, x, y);
            
            if (image)
            {
                osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension(ext);
                if (rw)
                {
                    std::string mime = "image/png";
                    if (ext == "jpeg" || ext == "jpg")
                    {
                        mime = "image/jpeg";
                    }                    
                    response.setContentType(mime);
                    std::ostream& ostr = response.send();                 
                    rw->writeImage(*image.get(), ostr);                    
                }             

            }
        }
 
        response.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);                
    }
开发者ID:Fabrice17,项目名称:osgearth,代码行数:42,代码来源:osgearth_server.cpp


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