tcf22 has asked for the wisdom of the Perl Monks concerning the following question:

I'm working onthis project and I have to send data to a cgi script, but I have to send the message in the body of the message and not in the headers.

I think I have the message sending correctly, but I don't know how to get the cgi script to read the message body. Normally data is sent as post data and I just read from STDIN, but when I tried that I just recieve <tt>. It looks like the message is there because the content length is 24, but I don't know where to read from.

Replies are listed 'Best First'.
Re: Recieving data in the body
by Ovid (Cardinal) on May 19, 2003 at 15:59 UTC

    If you're reading the data from STDIN, then this implies that you have a broken CGI parser. Generally from the perspective of your program, you should not care whether or not the data is coming via a POST or a GET.

    You might want to check out my CGI course, particularly Lesson 2, which explains why hand-rolled parsers are usually broken.

    The easiest way to deal with your problem is to use CGI.pm. For example, if the message is in a textarea named "message", you can read it with the following:

    use CGI qw(:standard); my $message = param('message');

    Pretty simple, eh? :)

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

      I've used the cgi module to recieve simple data sent in a get or a post. The cgi script that I am writing is just for testing to see if the data is correct.

      The spec that I am writing for says the data I send shouldn't be sent as a set of key value pairs, but actually in the body of the message. Maybe I'm misinterpreting what they want sent.

      Is there a CGI function that will handle this? Anytime I've ever sent anything to a script(through LWP, etc.) I always have sent key value pairs.
Re: Recieving data in the body
by jdporter (Paladin) on May 19, 2003 at 15:56 UTC
    It sounds like you are not using the CGI module. If you use CGI, it will take care of all that headache for you.

    Now, you say you have the sending part working; if so, fine. However, you might want to consider using the WWW::Mechanize module to handle the nitty-gritty of talking to cgi forms.

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

Re: Recieving data in the body
by arthas (Hermit) on May 19, 2003 at 15:57 UTC
    The content should be there,a nd you should be able to retrieve it reading from STDIN.

    However, beware that, if you created a new query using CGI.pm, STDIN might already have been read.

    Michele.
Re: Recieving data in the body
by hardburn (Abbot) on May 19, 2003 at 15:58 UTC

    Do you control the CGI that you're sending data to? Are you using CGI? If not, you should be. It handles all this stuff for you.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Re: Recieving data in the body
by tcf22 (Priest) on May 19, 2003 at 17:14 UTC
    Thanks for your help.

    I found the answer. Since it isn't sent as key value pairs, a bogus key 'keywords' is populated with the data that I need. The following code did the trick
    use CGI; my $cgi = new CGI; my $message = $cgi->param('keywords');