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. :)

Comments

  • ActiveX
    ActiveX Posts: 59
    and of course, how to receive POST data?
  • woboyle
    woboyle 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.
  • marc
    marc 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
  • ActiveX
    ActiveX 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>.
  • woboyle
    woboyle Posts: 501
    I believe that the POST data is passed to the stdin of the CGI program.
  • ActiveX
    ActiveX 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
  • jabirali
    jabirali 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.
  • ActiveX
    ActiveX 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 ;-)
  • jabirali
    jabirali Posts: 157
    Have you tried doing something like this?
    #include <iostream>
    #include <sstream>
    #include <string>
    using namespace std;
    
    int main()
    {
    	stringstream ss;
    	ss << cin.rdbuf();
    
    	cout << "Content-type: text/html\\n\\n<html><body>\\n"
    	     << "Data received:\\n" << ss.str() << "\\n</body></html>\\n";
    
    	return 0;
    }
    
  • ActiveX
    ActiveX Posts: 59
    Hell! it works! Thanks Jabir. ;-)
  • jabirali
    jabirali Posts: 157
    I'm glad I could help :)
  • tom36
    tom36 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

Categories

Upcoming Training