Search code examples
c++poco-libraries

get URL params with Poco library


I'm developing a web server with Poco library. When my server receive a HTTP request with form data in GET mode, I don't know how to use the class HTMLForm to show a list with received pairs param=value.

With request.getURI().getQuery() I am able to get the complete string. I guess I can split the string in the traditional way, using a tokenizer.

Is there a better way to do it using Poco? Thanks


Solution

  • Ok, class HTMLForm inherits from class NameValueCollection, that implements an iterator useful to move through the pairs "name=value".

    This is the code that solve my problem:

    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;
    }