Solved

CGI and C/C++

Posted on 1997-04-20
1
224 Views
Last Modified: 2013-12-25
Hello everybody

I´m having trouble in "receiving" a form transmitted via POST method. My
program goes something like this:

#include "iostream.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "dos.h"
....
char *query_string;
if (getenv("REQUEST_METHOD")=="GET") query_string=getenv("QUERY_STRING");
else cin>>query_string;
....

I am using Visual C++ and Personal Web Server.
As POSTed forms are sent through stdin, I thought this should do the trick,
but it doesn´t. As I submit the form, my exe runs and hangs up my computer!
I think it is expecting data from stdin, but it should already be there!
I have no trouble with GET method, but sometimes I need to use POST.

Can anyone help me?

Thanks in advance
Ricardo Peres
Coimbra, Portugal
0
Comment
Question by:rjperes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
julio011597 earned 50 total points
ID: 1827928
Well, i don't know C++, but it seems that your program cannot work.

> if(getenv("REQUEST_METHOD") == "GET")
does not do what you need.
Include <string.h> for strcmp() and go like this:
if(!strcmp(getenv("REQUEST_METHOD"), "GET"))

> query_string = getenv("QUERY_STRING");
this is ok, but beware that if QUERY_STRING is empty, then query_string will be a NULL pointer; you should handle this case.

> else cin >> query_string;
Does cin allocate memory for query_string??
If not, as i suppose, you should do it yourself.
So the code should look something like this (a bit redundant, for clearness:):
--//--
char *temp;
size_t content_length; /* check size_t on your os: i.e. check type needed for malloc() parameter */
...
else {
  if(!(temp = getenv("CONTENT_LENGTH")) || !(content_lenght = (size_t)atol(temp)) {
    return NO_QUERY_STRING; /* or such */
  }
  else {
    if(!(query_string = malloc(content_length + 1))) {
      return MALLOC_FAILED; /* or such, again */
    }
    else cin >> query_string;
  }
}
...
--//--

Last, shouldn't be:
#include <iostream.h>
#include <stdlib.h>
... and so on??

HTH, julio
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question