cgicc - cgi.getElements(), which method? get or po

2019-07-23 08:07发布

cgicc can process form elements quite well , but how can i know whether the data is generated from get_method or post_method?

the piece of code i used:

cout << "Content-type:text/html\r\n\r\n";
try {    
    Cgicc cgi;
    const_form_iterator iter;
    for(iter = cgi.getElements().begin(); 
        iter != cgi.getElements().end(); 
        ++iter){
        cout << 
        "<table><tr>"   <<
        "<td>" << iter->getName() << "</td>"  << 
        "<td>" << iter->getValue() << "</td>" << 
        "</tr></table>" << endl;
    }
}catch(exception& e) {
    cout << e.what() << endl;
}

update:

i find this from the cgicc official page: "Parses both GET and POST form data transparently." (http://www.gnu.org/software/cgicc/)

it seems that cgicc don't want to separate get and post by design?

标签: c++ post web get cgi
2条回答
虎瘦雄心在
2楼-- · 2019-07-23 08:17

You can find the HTTP method (ì.e. GET, POST, etc...) of a request using cgicc::CgiEnvironment::getRequestMethod

查看更多
Luminary・发光体
3楼-- · 2019-07-23 08:19

I think the only way to solve it is by checking whether there is a variable name in the GET method query string that's the same name of the one in the POST method. This means that the variable name must be mentioned ONLY ONCE either of the two methods. In other words, if you combine the variables of the GET method with the variables of the POST in a single set, the variable name must be mentioned once in this set.

查看更多
登录 后发表回答