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


C++ HttpRequest::FormatRequest方法代码示例

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


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

示例1: test_request

static void test_request()
{
    static const struct {
            int         d_line;
            std::string d_input;
            std::string d_expected_output;
        } DATA[] = {
    // Check that inputs are normalized
        // LINE  // INPUT                                       // EXP
        {L_,     "GET http://google.com/ HTTP/1.1\r\n\r\n"    , "GET / HTTP/1.1\r\n"
                                                                "Host: google.com\r\n\r\n"},
        {L_,     "GET http://www.google.com/ HTTP/1.1\r\n\r\n", "GET / HTTP/1.1\r\n"
                                                                "Host: google.com\r\n\r\n"},
        {L_,     "GET www.google.com/ HTTP/1.1\r\n\r\n"       , "GET / HTTP/1.1\r\n"
                                                                "Host: google.com\r\n\r\n"},
        {L_,     "GET google.com/ HTTP/1.1\r\n\r\n"           , "GET / HTTP/1.1\r\n"
                                                                "Host: google.com\r\n\r\n"},
    // Check a HEAD Request
        // LINE  // INPUT                                       // EXP
        {L_,     "HEAD http://google.com/ HTTP/1.1\r\n\r\n"   , "HEAD / HTTP/1.1\r\n"
                                                                "Host: google.com\r\n\r\n"},
                                                               
    // Check a request with a PATH
         {L_,    "GET http://cs.ucla.edu" 
                 "/classes/fall13/cs111/news.html " 
                 "HTTP/1.1\r\n\r\n"                           ,    
                                                                "GET /classes/fall13/cs111/news.html HTTP/1.1\r\n"
                                                                "Host: cs.ucla.edu\r\n\r\n"},
    // Check a request with more headers
        {L_,     "GET http://cs.ucla.edu" 
                 "/classes/fall13/cs111/news.html " 
                 "HTTP/1.1\r\n"
                 "Accept-Encoding: identity\r\n"
                 "If-Modified-Since: Sat, 15 Feb 2014 17:00:59 GMT\r\n\r\n",
                                                                
                                                                "GET /classes/fall13/cs111/news.html HTTP/1.1\r\n"
                                                                "Host: cs.ucla.edu\r\n"
                                                                "Accept-Encoding: identity\r\n"
                                                                "If-Modified-Since: Sat, 15 Feb 2014 17:00:59 GMT\r\n\r\n"},
    };
        
    const size_t NUM_DATA = sizeof (DATA) / sizeof (*DATA);
    
    for (size_t ti = 0; ti < NUM_DATA; ++ti) {
        const int     LINE       = DATA[ti].d_line;
        const char   *INPUT      = DATA[ti].d_input.c_str();
        const size_t  LEN_INPUT  = DATA[ti].d_input.length();
        const char   *EXP_OUTPUT = DATA[ti].d_expected_output.c_str();
        
        char         *output     = new char[LEN_INPUT];
        
        if (veryVeryVerbose) { T_ P(LINE) };
        HttpRequest req;
        req.ParseRequest(INPUT, LEN_INPUT);
        req.FormatRequest(output);
        ASSERT(0 == strcmp(output, EXP_OUTPUT))
    }
}
开发者ID:mickeysweatt,项目名称:Networking,代码行数:58,代码来源:main.cpp


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