Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > CGI/C++ Problem with Microsoft IIS

Reply
Thread Tools

CGI/C++ Problem with Microsoft IIS

 
 
Steve B
Guest
Posts: n/a
 
      09-01-2005
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


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-01-2005
Steve B wrote:
> 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.
> [...]
>
> 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?


Doesn't seem to be a C++ _language_ problem. Please try to find more
appropriate newsgroup in the "microsoft.public." hierarchy.

V
 
Reply With Quote
 
 
 
 
Default User
Guest
Posts: n/a
 
      09-01-2005
Steve B wrote:

> 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.


It's unlikely you have a C++ problem, so you need a different
newsgroup. I'd start with comp.infosystems.www.authoring.cgi.




Brian
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      09-01-2005
Steve B wrote:
> 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?
>


Yes the problem is that cin is not opened in binary mode. On some
platforms (e.g. Windows) conversion of line ending characters (which are
permitted because the stream is not open in binary mode) means that
exact counts of numbers of bytes to read are not accurate. Basically
Windows has converted at \r\n sequence into \n which means that you end
up with one less character thane xpected. This issue does not exist on Unix.

So, you question is perfectly legitimate for c.l.c++, the bad news
though is that there is no standard way to force cin into binary mode.
So your question has no answer in standard C++.

John
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSD 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments