Read parameters - POCO C++
I am a beginner, trying to learn how to use POCO C++ library ( http://pocoproject.org/ )
Suppose I have an HTML which has some input elements (say 开发者_开发知识库a text-box, check-box, etc.)
<html>
<body>
<form action="xyz.html" method="GET">
<input type="text" name="text1" id="text1" />
<input type="submit" />
</form>
</body>
<html>
After hitting the submit button, how do I read these values at the server side from the request object?
Could anyone please also explain how to this is done when POST method is used?
You may want to check out the HTTPFormServer
sample project provided with the POCO libraries.
It shows how to read form parameters both with GET and POST methods.
Basically it extends the abstact class HTTPRequestHandler
.
In the override of the handleRequest()
method, it uses MessageHeader::splitParameters()
to parse the form parameters.
Once you have downloaded the library, you can find the sample in:
<install_dir>\Net\samples\HTTPFormServer
This shuld work
// parse html form
HTMLForm form( request );
NameValueCollection::ConstIterator iterator = form.begin();
while (iterator != form.end()){
BOOST_LOG_TRIVIAL(info) << iterator->first << ": " << iterator->second;
iterator++;
}
Hope it helps.
精彩评论