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

試著忘記壹切 提交于 2019-12-11 03:59:40

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/19088719/cgicc-cgi-getelements-which-method-get-or-post

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!