Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Feb 1999 07:18:58 -0800
From:      "Dan O'Connor" <dan@jgl.reno.nv.us>
To:        <keith@apcs.com.au>, <questions@FreeBSD.ORG>
Subject:   Re: www cgi forms 
Message-ID:  <05a401be59bf$ade2cc60$0200000a@danco.home>

next in thread | raw e-mail | index | archive | help
The arguments from a form don't get passed as argv[] arguments. If your form
uses METHOD=POST, you must read $CONTENT_LENGTH characters from standard
input (stdin). If you use METHOD=GET the args are in $QUERY_STRING.

here's the algorith I use (sorry, it's in Perl, but you can convert it to
C):

# Parse the form

# Get the input
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
    $buffer = $ENV{'QUERY_STRING'};
}
else {
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}

# Split the name-value pairs
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs) {
        ($name, $value) = split(/=/, $pair);
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        $FORM{$name} = $value;
    }
}

Have fun!

--Dan

-----Original Message-----
From: Keith Anderson <keith@apcs.com.au>
To: questions@FreeBSD.ORG <questions@FreeBSD.ORG>
Date: Tuesday, February 16, 1999 1:37 AM
Subject: www cgi forms


>Hi All
>
>I'm having a problem passing information to my cgi's.
>I made a little test program to echo back anything I sent it (see below
eecho.c)
>
>sf I use <ISINDEX> all works fine but if I try a form nothing happens it
runs
>the script but with no arg's
>
>
>Can some one point me to the right direction on this one.
>
>Thanks
>
>Keith Anderson
>
>
>
><snip eecho.c>
>#include <stdio.h>
>#include <stdlib.h>
>
>int a;
>
>main(int argc, char * argv[])
>{
>printf("Content-type: text/html\n\n");
>printf("<html>\n<head>\n<title>Arg Test</title>\n</head><body>\n");
>printf("argc = %d\n",argc-1);
>if (argc > 1)
>        {
>        printf("Args  are\n");
>        for (a = 1;a<argc;a++)
>                printf("%s\n",argv[a]);
>        }
>printf("</body>\n</html>\n");
>exit(0);
>}
>
></snip>
>---
>
>"The box said 'Requires Windows 95, NT, or better,' so I installed
FreeBSD."
>
>
>----------------------------------
>E-Mail: Keith Anderson <keith@apcs.com.au>
>Date: 16-Feb-99
>Time: 20:20:29
>Satelite Service 64K to 2Meg
>This message was sent by XFMail
>----------------------------------
>
>To Unsubscribe: send mail to majordomo@FreeBSD.org
>with "unsubscribe freebsd-questions" in the body of the message
>


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?05a401be59bf$ade2cc60$0200000a>