Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem getting POST info through stdin using C++

Status
Not open for further replies.

greedyzebra

Technical User
Sep 5, 2001
140
US
Why can I not receive POSTed form results via stdin? The first line of my C++ program is: cin >> buffer; The program just hangs. I've also used fgets(buffer, 255, stdin);, but have the same result.

Also, I'm new to CGI and in all of the reference materials I've recently consulted tell me that information submitted with the GET method should come into a C++ program via argv[1]. However, I never receive more than one command line argument.

One suggestion was the permissions on the folder containing the .exe, but the current config on that is that "Everyone" has "Full Control."

I've had this problem on three servers, two running on Windows, the other Unix.

Thanks in advance for any help/tips,

Tom
 
The web server makes GET-method data available in the environment variable QUERY_STRING, not in argv[]. This is standard CGI.

What web server have you tried to run your programs with? ______________________________________________________________________
TANSTAAFL!
 
This is the information provided by the env variable SERVER_SOFTWARE: Microsoft-IIS/5.0.

I'm not having any problems running my programs, just getting input to them. I have noticed that when using GET the QUERY_STRING env var contains the info. However, I would much prefer to use POST so the info is not visible in the URL.

It's interesting that you say the QUERY_STRING is CGI standard... One of the frustrating things about this problem is that *every* book/web site I've consulted mentions GET info being transferred via argv!

Thanks for your reply,

Tom
 
I don't know...
These guys:

Say that these guys:

are the maintainers of the CGI spec, and the NCSA site says here:

the GET-method query data MUST be in QUERY_STRING. Anyway, your empirical evidence supports my version, doesn't it?



What happens when you invoke the program and pipe some file into it?

On unix:
cat <somefile> | <your program>

On Win32:
type <somefile> | <your program>

Does it still hang? ______________________________________________________________________
TANSTAAFL!
 
Here's test code I've written that works for me under Apache on Linux:

The HTML file that does the input:
Code:
<html><body>
<form method=POST action=test_bin_cgi.cgi>
	<input name=foo type=text>
	<input name=bar type=text>
	<input type=submit>
</form>
</body></html>[code]

Here's my c++ code:
[code]#include <iostream.h>
#define SIZE 1024

int main ()
{
	char buffer[SIZE];
	unsigned int counter;
	
	for (counter = 0; counter < SIZE; counter++)
	{
		buffer[counter] = '\0';
	}

	cin >> buffer;
	cout << &quot;Content-type: text/plain;&quot; << endl << endl;
	cout << buffer;
}


If I pull up the HTML file in my browser, put &quot;a&quot; in the field &quot;foo&quot; and &quot;b&quot; in the field &quot;bar&quot;, this is what I get to my browser:

foo=a&bar=b ______________________________________________________________________
TANSTAAFL!
 
Hello,

Here's what I've now tried (all with the same results, that the program hangs because it's waiting for input that obviously never comes):

I've copied sleipnir214's code verbatim (including the html form; though I obviously changed the &quot;action&quot; value to represent the URL for the cgi-bin on my site). I've tried cin and fread. I've made sure the read statements are the first thing, even before the &quot;Content-type&quot; message, just to make sure I'm not affecting the input stream.

I also tried sleipnir214's suggestion of piping a file to the program and the program functions as it should. Since *every* document I've referenced on this subject says POST sends the information to stdin, I just can't help but think that it's got to be something related to the *#$&(# Microsoft Web Server.

I hope someone can help, because having username and passwords show up in the URL is obviously unacceptable!

I don't know Perl, but perhaps someone can provide code for a simple script that would merely echo the query string that's sent with the POST method (that's all I'm trying to do in C++ right now). I'd love to find anything that would work.

Thanks,

Tom
 
A very brief peice of perl that will show any values submitted from the HTML form (POST or GET).

Code:
#!/usr/local/bin/perl
use CGI;
my $cgi_object = new CGI;
print $cgi_object->header,
      $cgi_object->start_html,
      $cgi_object->Dump,
      $cgi_object->end_html;
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
greedyzebra,

Yeah, I'm having the same problem with IIS 5. Unfortunately, the last time I did this, it was with IIS 4.

I recommend that you post your question in the IIS forum. The problem seems to be with IIS specifically. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top