Chris wrote:
Hi, I'm using CGI with MS IIS and Visual Studio 2003.
CGIs simply call programs and communicate with them via stdin/stdout. Can
you reproduce the problem outside IIS?
My problem is when I'm trying to read post data, I use
cin.get(buffer, size), where buffer is a new char[size + 1] and size
is the atoi of getenv("CONTENT_LENGTH").
atoi() has its dangers, so I wouldn't use it. 'new' also has its dangers,
so a 'vector<char> buffer(size+1)' should be better.
My problem is, it cuts off one character at the end. And if I use
cin.get(buffer, size + 1), it just sits there waiting for more data.
Do I have to roll my own solution, or use fread? Is there some way to
use cin.get work for me, without having to call it twice (the second
time calling cin.get(buffer[size-1])?
Chris, I'm only guessing what could cause that, but are you perhaps
bitten by the CR/LF conversion from DOS? I know that HTTP uses '\r\n' as
line terminator and that probably includes the content length. If your
program then reads a line and has the CR/LF converted to a single '\n',
you will obviously be short one character.
Uli