[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

CGI and C/C++

Posted on 1997-04-20
1
Medium Priority
?
235 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 100 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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 threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

656 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