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


C++ HTTPMessage::getQueryParam方法代码示例

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


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

示例1: clear

TEST(HTTPMessage, TestParseQueryParamsSimple) {
  HTTPMessage msg;
  string url = "/test?seq=123456&userid=1256679245&dup=1&dup=2&helloWorld"
               "&second=was+it+clear+%28already%29%3F";

  msg.setURL(url);
  EXPECT_EQ(msg.getQueryParam("seq"), "123456");
  EXPECT_EQ(msg.getQueryParam("userid"), "1256679245");
  EXPECT_EQ(msg.getQueryParam("dup"), "2");
  EXPECT_EQ(msg.getQueryParam("helloWorld"), "");
  EXPECT_EQ(msg.getIntQueryParam("dup", 5), 2);
  EXPECT_EQ(msg.getIntQueryParam("abc", 5), 5);
  EXPECT_EQ(msg.getDecodedQueryParam("second"), "was it clear (already)?");
  EXPECT_EQ(msg.getDecodedQueryParam("seq"), "123456");
  EXPECT_EQ(msg.hasQueryParam("seq"), true);
  EXPECT_EQ(msg.hasQueryParam("seq1"), false);
  EXPECT_EQ(msg.getIntQueryParam("dup"), 2);
  EXPECT_ANY_THROW(msg.getIntQueryParam("abc"));
  EXPECT_ANY_THROW(msg.getIntQueryParam("second"));
}
开发者ID:abhiguru,项目名称:proxygen,代码行数:20,代码来源:HTTPMessageTest.cpp

示例2: sort

TEST(HTTPMessage, TestParseQueryParamsComplex) {
  HTTPMessage msg;
  std::vector<std::vector<std::string>> input = {
    {"", "", ""},
    {"key_and_equal_but_no_value", "=", ""},
    {"only_key", "", ""},
    {"key_and_value", "=", "value"},
    {"key_and_value_2", "=", "value2"},
    {"key_and_value_3", "=", "value3"}
  };

  for (int i = 0; i < (1 << input.size()); ++i) {
    std::vector<std::vector<std::string>> sub;
    for (size_t j = 0; j < input.size(); ++j) {
      if ((i & (1 << j))) {
        sub.push_back(input[j]);
      }
    }

    sort(sub.begin(), sub.end());
    do {
      bool first = true;
      std::string url = "/test?";
      for (const auto& val: sub) {
        if (first) {
          first = false;
        } else {
          url += "&";
        }

        url += val[0] + val[1] + val[2];
      }

      msg.setURL(url);
      for (const auto& val: sub) {
        if (val[0].empty()) {
          continue;
        }

        EXPECT_EQ(val[2], msg.getQueryParam(val[0]));
      }

    } while (next_permutation(sub.begin(), sub.end()));
  }
}
开发者ID:abhiguru,项目名称:proxygen,代码行数:45,代码来源:HTTPMessageTest.cpp


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