cgi post - clear data from stdin

Discussion in 'C++' started by Oliver Bleckmann, Nov 28, 2006.

  1. hey guys,
    i have a little problem. my cgi routines are working so far,
    but i need to redirect to the cgi-programm and what the
    "posted" data to be cleared if redirected. i don't know
    how the post method exactly works. maybe i have to
    clear the stdin (tried fflush)!? maybe the is another reason
    that the former data is displayed. fist i thought of the browser
    cach, but it's the same problem using ctrl+f5.
    i need to check if the cgi program is called with form data
    or not, because checking the request method does not work either.
    any ideas?

    code:

    .....
    std::string meth_s = null_to_empty(std::getenv("REQUEST_METHOD"));
    if (meth_s == "")
    {
    cout << "EMPTY" << endl;
    // code in case no data is passed, doesn't work, because
    of the persistent post data and
    // it seems, that every url call ist a "get" command !?
    }
    else if (meth_s == "GET")
    {
    query = null_to_empty(getenv("QUERY_STRING"));
    cout << "GET" << endl;
    cout << query << endl;
    } else if (meth_s == "POST")
    {
    // This is the routine for the query string, which
    should be parsed and cleared on every program call, but remains even on a
    ctrl+f5 refresh
    int len = atoi(getenv("CONTENT_LENGTH"));
    input = new char[len+1];
    fread(input, 1, len, stdin);
    input[len] = 0;
    cout << "POST" << endl;
    query = input;
    cout << query << endl;
    delete input;
    //fflush ( stdin );
    } else cout << "NONE" << endl;
    .......
     
    Oliver Bleckmann, Nov 28, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johnathan Doe

    peek at stdin, flush stdin

    Johnathan Doe, May 15, 2004, in forum: C Programming
    Replies:
    5
    Views:
    25,085
    Chatoyer
    May 17, 2013
  2. Charlie Zender

    Reading stdin once confuses second stdin read

    Charlie Zender, Jun 19, 2004, in forum: C Programming
    Replies:
    6
    Views:
    794
    Dan Pop
    Jun 21, 2004
  3. Ben
    Replies:
    2
    Views:
    1,355
    jacob navia
    Aug 29, 2009
  4. Terry Cooper
    Replies:
    7
    Views:
    428
    Janos Sebok
    Jun 9, 2009
  5. Stefano Sabatini
    Replies:
    6
    Views:
    297
    Stefano Sabatini
    Jul 29, 2007
Loading...

Share This Page