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

  • ActiveXActiveX Posts: 59
    and of course, how to receive POST data?
  • woboylewoboyle 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.
  • marcmarc 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
  • ActiveXActiveX 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>.
  • woboylewoboyle Posts: 501
    I believe that the POST data is passed to the stdin of the CGI program.
  • ActiveXActiveX 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
  • jabiralijabirali 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.
  • ActiveXActiveX 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 ;-)
  • jabiralijabirali 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;
    }
    
  • ActiveXActiveX Posts: 59
    Hell! it works! Thanks Jabir. ;-)
  • jabiralijabirali Posts: 157
    I'm glad I could help :)
  • tom36tom36 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

Sign In or Register to comment.