Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

accepting post data in web executable

when building a web executable, how do you accept input? i understand it must be sent back to the web executable thru a form (POST), and i know how to cout >> to the browser and all ... but how do you tell the exe that this data here thats being slung at it, is the POST data?

is it the argc argv, command line arguments that will represent the POST data-incoming?

is the question clear or should i put down the b0ng and re-write my ?? ....

thanks-
f_dude
0
funkydude
Asked:
funkydude
  • 2
  • 2
1 Solution
 
imadjinnCommented:
The data into CGI actually gets sent through stdin (for post data), so you could read it from stdin using a file pointer or an istream (cin).  You could also wrap a socket around it and get it through recv, which I think is cleaner but actually takes a little more learning.  If you use argc and argv directly, you have a problem determining where the end of the post data is (since spaces can be intermixed with the rest of the data; and you wouldn't know how many spaces or if they're tabs or whatever).  Use cin.read().  Good luck.
0
 
funkydudeAuthor Commented:
hi

thanks for the great reply ... ill throw an extra 50pts if you can point me to some sample code i can learn from, as a model/example.

thank you again-
f_dude
0
 
imadjinnCommented:
Try this... it should get you on the right track.

#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

string GetParameters()
{
  char *request_method = getenv("REQUEST_METHOD");
  if(request_method == NULL)
    return "";

  if(! strcmp(request_method, "GET"))
  {
    char *env = getenv("QUERY_STRING");
    if(env != NULL)
      return env;
    else
      return "";
  }
  else if(! strcmp(request_method, "POST"))
  {
    string parameters;
    int length = atoi(getenv("CONTENT_LENGTH"));
    for(int i = 0; i < length; ++i)
    {
      parameters += getc(stdin);
    }

    return parameters;
  }
  else
    return "";
}

int main(int argc, char **argv, char *envp[])
{
  cout << "Content-type: text/html\n\n";
  cout << "<html><body>";

  for(int i = 0; envp[i] != NULL; ++i)
  {
    cout << "<br/>" << envp[i] << endl;
  }

  cout << "<br/>QUERY = " << GetParameters() << endl;
  cout << "</body></html>\n";

  return 0;
}
0
 
funkydudeAuthor Commented:
its a great thing when someone helps you learn a new 'thing... greatly appreciated!

f_dude
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now