使用 Poco 库获取 URL 参数
get URL params with Poco library
我正在开发一个带有Poco库的Web服务器。当我的服务器在GET模式下收到带有表单数据的HTTP请求时,我不知道如何使用类HTMLForm
显示包含已接收对param=value
的列表。
有了request.getURI().getQuery()
我能够获得完整的字符串。我想我可以使用分词器以传统方式拆分字符串。
有没有更好的方法来使用 Poco 做到这一点?谢谢
好的,类 HTMLForm 继承自类 NameValueCollection,它实现了一个迭代器,可用于在 "name=value" 对之间移动。
这是解决我问题的代码:
string name;
string value;
HTMLForm form( request );
NameValueCollection::ConstIterator i = form.begin();
while(i!=form.end()){
name=i->first;
value=i->second;
cout << name << "=" << value << endl << flush;
++i;
}
使用 poco 版本 1.11.0-all (2021-06-28)您可以这样做:
const Poco::URI Uri(request.getURI());
const Poco::URI::QueryParameters QueryParms = Uri.getQueryParameters();
Poco::URI::QueryParameters
是:
std::vector<std::pair<std::string, std::string>>
POCO "NameValueCollection" 几乎与 Vettrasoft Z Directory 相同namevalue_set_o类,记录在此处:
http://www.vettrasoft.com/man/zman-strings-namevalue_set.html
这至少提供了一些示例代码。我遇到的最大问题POCO 缺乏有关如何使用它的示例或解释(包括参考手册页)。对于 Z 目录的名称-值集类,与上述等效的源代码如下所示:
using namespace std;
int i, ie;
namevalue_set_o nv;
string_o s = "FOO=BAR;DATE="12/21/2012";HOST=vertigo;OSTYPE="Windows Vista"";
nv.load_from_string(s);
i = 0;
while (i < nv.size())
{
const namevalue_pair_o &item = nv.get(i, &ie);
if (!ie)
cout << item.name() << "=" item.value() << endl << flush;
++i;
}
相关文章:
- 如何反转整数参数包
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 函数调用中参数的顺序重要吗
- 部分定义/别名模板模板参数
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 使用不带参数的函数访问结构元素
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何使用Luacneneneba API正确读取字符串和表参数
- 在派生函数中指定void*参数
- Qml:从文件加载组件时将参数作为 URL 的一部分传递
- 使用 Poco 库获取 URL 参数
- 获取url参数值以某种格式编码
- xml读取内存 - 未知'url'参数
- 如果URL作为参数提供,c++ curl无法解析host