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.

I've received a few responses to this exact thread in the CGI forum, but wanted to post it here, too, since I'm coding in C++.

TIA,

Tom

 
To read POST information from CGI in C is the same as reading data from stdin. Yours code should be fine in this sense. I think you probably have error somewhere. Post your code. So that others can see what is the real problem.

Try the following code, it shall print everything you posted from the webpage.

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void main()
{
int len=atoi(getenv(&quot;CONTENT_LENGTH&quot;));
char* text=(char*) malloc(len+1);
fread(text, 1, len, stdin);
text[len+1]='\0';

printf(&quot;Content-type: text/html\n\n&quot;);
printf(&quot;%s&quot;,text);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top