Solved

CGI and C/C++

Posted on 1997-04-20
1
228 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
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.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

690 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