Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cgi and c++

80 views
Skip to first unread message

Tomas Garijo

unread,
Mar 11, 2015, 12:16:45 PM3/11/15
to
Hello,

I'm noob in c++. My problem is next. A linux system, is sending to my apache server a xml stream by http post. I need capture by CGI this stream xml and parsec it, but i don't know how to do this. The major problem is capture the xml stream. I don't know if i need a GCI API or Socket API. Please can you help me?

Regards.

Lőrinczy Zsigmond

unread,
Mar 11, 2015, 12:22:32 PM3/11/15
to
In CGI, the POST-data comes from the standard input,
so simply use fgets/fread/etc on standard input.

Drew Lawson

unread,
Mar 11, 2015, 3:13:53 PM3/11/15
to
In article <mdpq3k$brm$1...@speranza.aioe.org>
=?UTF-8?B?TMWRcmluY3p5IFpzaWdtb25k?= <zs...@nospam.for.me> writes:
>In CGI, the POST-data comes from the standard input,
>so simply use fgets/fread/etc on standard input.

The content of the post is on the standard input, but the size in
in the HTTP variable CONTENT_LENGTH. That is retrieved as an
environment variable. The CGI spec does not require end-of-file
at the end of data. I know from experience that Apache 1.3 did not
do that. I've never tested whether Apache 2 does.


--
Drew Lawson | Pass the tea and sympathy
| for he good old days are dead
| Let's raise a toast to those
| who best survived the life they led

Lőrinczy Zsigmond

unread,
Mar 12, 2015, 10:33:12 AM3/12/15
to
On 2015-03-11 20:13, Drew Lawson wrote:

> > In CGI, the POST-data comes from the standard input,
> > so simply use fgets/fread/etc on standard input.

> The content of the post is on the standard input, but the size in
> in the HTTP variable CONTENT_LENGTH. That is retrieved as an
> environment variable.

Thank you!

Let's mention that Apache and CGI communicate via unnamed pipes
(at least in the test-program I quickly created); the CGI
doesn't inherit the original socket-handle from Apache.

Lynn McGuire

unread,
Mar 12, 2015, 12:57:06 PM3/12/15
to
I use the CGIC library on my webserver.
http://www.boutell.com/cgic/

Lynn

woodb...@gmail.com

unread,
Mar 12, 2015, 10:23:41 PM3/12/15
to
What do you use it for? I used to use that library also.
Now I use a binary protocol rather than http and C++ rather
than C.


Brian
Ebenezer Enterprises
http://webEbenezer.net

Lynn McGuire

unread,
Mar 13, 2015, 12:33:39 PM3/13/15
to
For processing queries on my webserver. All of my server side apps are written in C++.

Lynn

Tomas Garijo

unread,
Mar 16, 2015, 11:04:41 AM3/16/15
to
Hello,

I don't know what happend with my code, but I can't receive xml data by http post.

This is my code

int main(int argc, char *argv[])
{
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>\n";
cout << "<head>\n";
cout << "<title>CGI Envrionment Variables</title>\n";
cout << "</head>\n";
cout << "<body>\n";


//cout << "<p>" << *argv[1] << "</p>" << endl;
//cout << "argc = " << argc << endl;
//cout << "argc =0 " << argv[0] << endl;


char *inputlenstr;
char *tmp;
int inputlen;
int status;

cout << "Tmp= " << *tmp << endl;

inputlenstr = getenv("CONTENT_LENGTH");
inputlen = atoi(inputlenstr);
status = fread(tmp, 1, inputlen, stdin);

cout << "Status= " << status << endl;
cout << "Tmp= " << *tmp << endl;

cout << "</body>\n";
cout << "</html>\n";

}

and this is a python program that send xml file (sorry for use python)

import requests
url = 'http://192.168.3.32/cgi-bin/xmlengine'
data = open('.//file.xml', 'r').read()
r = requests.post(url, data=data)
print(r.text)


This is the result

<html>
<head>
<title>CGI Envrionment Variables</title>
</head>
<body>
argc = 1
argc =0 /var/www/.netbeans/remote/192.168.3.32/tgarijow7-Windows-x86_64/P/xmleng
ine/dist/Debug/GNU-Linux-x86/xmlengine
Tmp= |
Status= 0
Tmp= |
</body>
</html>

PD: I used a java program to send xml file by http post and I have had the same result.

Regards

Drew Lawson

unread,
Mar 16, 2015, 11:28:03 AM3/16/15
to
In article <3635c923-06ce-494d...@googlegroups.com>
Tomas Garijo <tga...@gmail.com> writes:

>This is my code
>

[snip]

> char *inputlenstr;
> char *tmp;
> int inputlen;
> int status;
>
> cout << "Tmp= " << *tmp << endl;
>
> inputlenstr = getenv("CONTENT_LENGTH");
> inputlen = atoi(inputlenstr);
> status = fread(tmp, 1, inputlen, stdin);
>
> cout << "Status= " << status << endl;
> cout << "Tmp= " << *tmp << endl;

In all of this, tmp is an uninitialized pointer.



--
Drew Lawson

". . . And I never give a reason"
-- God, as channeled by Seven Nations

Victor Bazarov

unread,
Mar 16, 2015, 11:32:20 AM3/16/15
to
On 3/16/2015 11:04 AM, Tomas Garijo wrote:
> El miércoles, 11 de marzo de 2015, 17:16:45 (UTC+1), Tomas Garijo escribió:
>> Hello,
>>
>> I'm noob in c++. My problem is next. A linux system, is sending to my apache server a xml stream by http post. I need capture by CGI this stream xml and parsec it, but i don't know how to do this. The major problem is capture the xml stream. I don't know if i need a GCI API or Socket API. Please can you help me?
>>
>> Regards.
>
>
> Hello,
>
> I don't know what happend with my code, but I can't receive xml data by http post.
>
> This is my code
> [..]

If your program compiles and runs, it's probably fine AFA C++ language
is concerned. Please post your CGI quesitons to an HTTP or CGI
newsgroup. I recommend news:comp.infosystems.www.authoring.cgi .

Sending and receiving files using HTTP is not part of C++ language.

V
--
I do not respond to top-posted replies, please don't ask

Tomas Garijo

unread,
Mar 16, 2015, 12:04:22 PM3/16/15
to
El miércoles, 11 de marzo de 2015, 17:16:45 (UTC+1), Tomas Garijo escribió:
I have the solution with the library Cgicc

Code:

Cgicc cgi;

const CgiEnvironment& env = cgi.getEnvironment();

cout << env.getPostData();

Thanks to all

Regards

0 new messages