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


C++ CCgiContext::GetSelfURL方法代码示例

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


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

示例1: ProcessRequest

int CCgiSampleApplication::ProcessRequest(CCgiContext& ctx)
{
    // Parse, verify, and look at cmd-line and CGI parameters via "CArgs"
    // (optional)
    x_LookAtArgs();

    // Given "CGI context", get access to its "HTTP request" and
    // "HTTP response" sub-objects
    const CCgiRequest& request  = ctx.GetRequest();
    CCgiResponse&      response = ctx.GetResponse();

 
    // Try to retrieve the message ('message=...') from the HTTP request.
    // NOTE:  the case sensitivity was turned off in Init().
    bool is_message = false;
    string message    = request.GetEntry("message", &is_message);
    if ( is_message ) {
        message = "'" + message + "'";
    } else {
        message = "<NONE>";
    }

    int iters = 5;
    for(int i = 0; i < iters; ++i) {
        PutProgressMessage( "Iteration " + NStr::IntToString(i) 
                            + " of " + NStr::IntToString(iters));
        SleepSec(5);
    }
    
    string this_host = CSocketAPI::gethostname();

    // Create a HTML page (using template HTML file "cgi_sample.html")
    auto_ptr<CHTMLPage> page;
    try {
        page.reset(new CHTMLPage("Sample Remote CGI", "rcgi_sample.html"));
    } catch (exception& e) {
        ERR_POST("Failed to create Sample CGI HTML page: " << e.what());
        return 2;
    }
    

    // Register substitution for the template parameters <@[email protected]> and
    // <@[email protected]>
    try {
        CHTMLPlainText* host = new CHTMLPlainText(this_host);
        page->AddTagMap("HOST", host);

        CHTMLPlainText* text = new CHTMLPlainText(message);
        page->AddTagMap("MESSAGE", text);

        CHTMLPlainText* self_url = new CHTMLPlainText(ctx.GetSelfURL());
        page->AddTagMap("SELF_URL", self_url);

        CHTMLPlainText* date = new CHTMLPlainText(
            GetFastLocalTime().AsString("D B Y, h:m:s"));
        page->AddTagMap("DATE", date);
    }
    catch (exception& e) {
        ERR_POST("Failed to populate Sample CGI HTML page: " << e.what());
        return 3;
    }

    // Compose and flush the resultant HTML page
    try {
        response.SetHeaderValue("Pragma", "no-cache");
        response.SetHeaderValue("Cache-Control", "no-cache");
        response.WriteHeader();
        page->Print(response.out(), CNCBINode::eHTML);

    } catch (exception& e) {
        ERR_POST("Failed to compose/send Sample CGI HTML page: " << e.what());
        return 4;
    }

    return 0;
}
开发者ID:,项目名称:,代码行数:76,代码来源:


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