473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

get(buffer, size) and CGI

Hi, I'm using CGI with MS IIS and Visual Studio 2003.

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

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])?
Dec 15 '07 #1
3 3466
Chris wrote:
Hi, I'm using CGI with MS IIS and Visual Studio 2003.

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

My problem is, it cuts off one character at the end.
cin.get(foo, n) will extract up to n-1 characters, so that is the expected
behavior. (The idea is that if you allocate n characters, you just continue
passing n around instead of having to do arithmetic on it.)
And if I use
cin.get(buffer, size + 1), it just sits there waiting for more data.
Hmm... that doesn't sound right. Just tested with Apache (don't have IIS),
and it worked fine. If you really need to get that method working for some
reason, try posting to an IIS- (or at least CGI-) specific group.
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])?
Try using std::string.

#incude <iostream>
#include <string>

int main() {
using namespace std;

cout << "Content-type: text/plain\r\n";
cout << "\r\n";

string post_data;
getline(cin, post_data);

// parse post_data, etc

return 0;
}

You don't even need to worry about Content-length.

--
Josh
Dec 15 '07 #2
On Dec 15, 9:01 am, Josh Sebastian <sebas...@gmail.comwrote:
Chris wrote:
Hi, I'm using CGI with MS IIS and Visual Studio 2003.
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").
My problem is, it cuts off one character at the end.

cin.get(foo, n) will extract up to n-1 characters, so that is the expected
behavior. (The idea is that if you allocate n characters, you just continue
passing n around instead of having to do arithmetic on it.)
And if I use
cin.get(buffer, size + 1), it just sits there waiting for more data.

Hmm... that doesn't sound right. Just tested with Apache (don't have IIS),
and it worked fine. If you really need to get that method working for some
reason, try posting to an IIS- (or at least CGI-) specific group.
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])?

Try using std::string.

#incude <iostream>
#include <string>

int main() {
using namespace std;

cout << "Content-type: text/plain\r\n";
cout << "\r\n";

string post_data;
getline(cin, post_data);

// parse post_data, etc

return 0;
}

You don't even need to worry about Content-length.

--
Josh
Well, I will try posting to an IIS group, but I suspected it was a
problem with my C++ compiler or my C++ code. The problem with using
getline is it doesn't fit the CGI standard, and when you get into
using multipart data, it could contain a text file, which would have
newlines in it already.
Dec 15 '07 #3
On Dec 15, 9:01 am, Josh Sebastian <sebas...@gmail.comwrote:
Chris wrote:
Hi, I'm using CGI with MS IIS and Visual Studio 2003.
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").
My problem is, it cuts off one character at the end.

cin.get(foo, n) will extract up to n-1 characters, so that is the expected
behavior. (The idea is that if you allocate n characters, you just continue
passing n around instead of having to do arithmetic on it.)
And if I use
cin.get(buffer, size + 1), it just sits there waiting for more data.

Hmm... that doesn't sound right. Just tested with Apache (don't have IIS),
and it worked fine. If you really need to get that method working for some
reason, try posting to an IIS- (or at least CGI-) specific group.
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])?

Try using std::string.

#incude <iostream>
#include <string>

int main() {
using namespace std;

cout << "Content-type: text/plain\r\n";
cout << "\r\n";

string post_data;
getline(cin, post_data);

// parse post_data, etc

return 0;
}

You don't even need to worry about Content-length.

--
Josh
I forgot to add, how would I go about viewing the state of cin (kinda
like extended cin.peek() and such)? You know, what it's got left in
it's buffer? Looking at the MS library source, it looks like cin.get
just keeps reading from cin.rdbuf()
Dec 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Joh | last post by:
hello, i'm looking for a way to get total size of an email (with its attached files) using library such as poplib, or ? can someone help me or give me an url from where to start ? thx
2
by: ViRtUaLpCwHiZ | last post by:
How would I get the size (In bytes or kilobytes) of a file on a typical HTTP web server. For example, I would like to get the file size of this file:...
5
by: Mark Overstreet | last post by:
I am writing a HTTPModule and all I want to do is trace the size of the page the client is requesting and that the web server is going to return. I tried the following code but it throws an...
13
by: TomislaW | last post by:
I need page size of generated aspx page, how and when I can get this information programmatically
13
by: Dino Buljubasic | last post by:
I want to get the size of a file stored in SQL Database (as image data type). Anybody knows how to do this? Any help will be greatelly appreciated
4
by: XxLicherxX | last post by:
Hello everyone, I need to get the size of a file using vb.net. I have tried using the Length property from the FileInfo class, but the values its returning aren't making any sense. For example,...
7
by: pattreeya | last post by:
Hello, how can I get the number of byte of the string in python? with "len(string)", it doesn't work to get the size of the string in bytes if I have the unicode string but just the length. (it...
0
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
I can get the value, fieldname, typename for a field from a DbDataReader... While Reader.Read For i As Integer = 0 To Reader.FieldCount - 1 value = Reader(i).ToString fieldname =...
2
by: moonrox | last post by:
Thanks for you help in advance. I am trying to use sp_helpdb to get the size of all the databases on a sql server. The results of sp_helpdb (when using the @dbname='databasename') is 2 sets of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.