Welcome to the Linux Foundation Forum!

writing cgi using C++

Hi

I'm writing a C++ program to run it as cgi. I need to receive input, and as I've found out looking up the net, the most fundamental way is to use getenv() from cstdlib.h.

I wanna know if there's any other interface to receiving environment variables, that is made for C++, I mean I look for equivalent of cstdlib.h in C++, IF EXISTS AT ALL.

Thanks. :)

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 59
    and of course, how to receive POST data?
  • Posts: 501
    ActiveX wrote:
    and of course, how to receive POST data?

    The system call interface to any CGI program/script is the same no matter the language the CGI was written in. This is documented in the HTML standards. You just need for your C/C++ program to process the passed arguments appropriately.
  • Posts: 647
    woboyle wrote:

    The system call interface to any CGI program/script is the same no matter the language the CGI was written in. This is documented in the HTML standards. You just need for your C/C++ program to process the passed arguments appropriately.

    I do not know much about this matter (if anything at all).

    Do you have any link where I could get introduced to all this CGI world?

    Thanks woboyle!

    Regards
  • Posts: 59
    Rubberman, what do you mean by that?
    Receiving GET data is as simple as using getenv("QUERY_STRING") , kid's stuff, but I need to handle much bigger data and therefore I have to use ... POST! you know.

    Please tell me clearly what should I do to receive post data?

    And also, I asked if there's any library that can be used instead of <stdlib.h> and is not based on <stdlib.h>.
  • Posts: 501
    I believe that the POST data is passed to the stdin of the CGI program.
  • Posts: 59
    Great!

    Well, do you "believe" that data is passed through stdin, or you're exactly 100% certain?

    And also, Rubberman, would you please tell me how to capture it?

    Thanks
  • Posts: 157
    According to Wikipedia, Rubberman is right: POST uses stdin to pass data to your CGI program. In C++, you should then be able to use the cin-stream to capture the data.
  • Posts: 59
    Thanks jabirali,

    Considering the fact that I've first explored the net and then picked the pen to weave a thread in forum, I already know that, and I've already used the most common methods of receiving data from cin, such as << and get(), but I know that here's something I don't know, say another member function of cin or something like that, that I don't know and is the key for me to going ahead.

    Most of the resources on the net are writing perl programs as CGI and rarely I can find some "useful" page on net to have talked about writing CGI using C++ and thus discussing the most common problems.

    I'll keep searching and trying other resources.

    But thanks anyway ;-)
  • Posts: 157
    Have you tried doing something like this?
    1. #include <iostream>
    2. #include <sstream>
    3. #include <string>
    4. using namespace std;
    5.  
    6. int main()
    7. {
    8. stringstream ss;
    9. ss << cin.rdbuf();
    10.  
    11. cout << "Content-type: text/html\\n\\n<html><body>\\n"
    12. << "Data received:\\n" << ss.str() << "\\n</body></html>\\n";
    13.  
    14. return 0;
    15. }
  • Posts: 59
    Hell! it works! Thanks Jabir. ;-)
  • Posts: 157
    I'm glad I could help :)
  • Posts: 1

    Its a great forum and I can discuss with anyone about many details to get and confusion if there is any like I wanted to australian essay hire someone to write essay for my college homework and had no idea where I can put my this kind of situation then one person helped me to find a genuine writing service online for middle school assignment to do in a proper way

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training