S
Steve B
Hi,
I've written a CGI program in C++ to handle form output via POST data. The
program works fine when Apache is the web server, but barfs when Microsoft
IIS is the web server. Here's the details.
The beginning of the program uses the following code to get the POST data.
int main()
{
// get the POST data string
int contentLength = atoi( getenv( "CONTENT_LENGTH" ) );
char* postString = new char[contentLength + 1];
string dataString;
string serverSoftware; // the web server software being used
( getenv( "SERVER_SOFTWARE" ) ? serverSoftware = ( char * ) ( getenv(
"SERVER_SOFTWARE" ) ) : serverSoftware = "" );
if ( contentLength )
{
// if ( serverSoftware.find( "IIS" ) != string::npos )
// {
// contentLength = contentLength - 1;
// }
cin.read( postString, contentLength );
postString[contentLength] = '\0';
dataString = postString;
}
.... rest of program ...
I've isolated exactly where the problem is with IIS -- it's the call to
cin.read. When using IIS and I uncomment the 4 lines in the if statement,
the call to cin.read works fine, but it doesn't read the last byte from the
POST data (which is critical). When these lines remain commented, the
program "hangs" -- I'm assuming because it is attempting to read past the
length of std input and just waits there indefinately.
When I run the above program with Apache, which works just fine with the 4
lines commented, here is some representative POST data that I output for
debugging purposes via the dataString variable:
quizFileName=..%2F098%2F098quiz.txt&C1=2&C2=4&C3=4&C4=2&C5=1&C6=2
After googling around for a day, I cannot find a reason for the difference
in behavior related to just using a different web server. Does anyone have
any ideas for me?
Thanks in advance,
Steve
I've written a CGI program in C++ to handle form output via POST data. The
program works fine when Apache is the web server, but barfs when Microsoft
IIS is the web server. Here's the details.
The beginning of the program uses the following code to get the POST data.
int main()
{
// get the POST data string
int contentLength = atoi( getenv( "CONTENT_LENGTH" ) );
char* postString = new char[contentLength + 1];
string dataString;
string serverSoftware; // the web server software being used
( getenv( "SERVER_SOFTWARE" ) ? serverSoftware = ( char * ) ( getenv(
"SERVER_SOFTWARE" ) ) : serverSoftware = "" );
if ( contentLength )
{
// if ( serverSoftware.find( "IIS" ) != string::npos )
// {
// contentLength = contentLength - 1;
// }
cin.read( postString, contentLength );
postString[contentLength] = '\0';
dataString = postString;
}
.... rest of program ...
I've isolated exactly where the problem is with IIS -- it's the call to
cin.read. When using IIS and I uncomment the 4 lines in the if statement,
the call to cin.read works fine, but it doesn't read the last byte from the
POST data (which is critical). When these lines remain commented, the
program "hangs" -- I'm assuming because it is attempting to read past the
length of std input and just waits there indefinately.
When I run the above program with Apache, which works just fine with the 4
lines commented, here is some representative POST data that I output for
debugging purposes via the dataString variable:
quizFileName=..%2F098%2F098quiz.txt&C1=2&C2=4&C3=4&C4=2&C5=1&C6=2
After googling around for a day, I cannot find a reason for the difference
in behavior related to just using a different web server. Does anyone have
any ideas for me?
Thanks in advance,
Steve