Tommi,
> So far I have known that I might be given a number of chars that I
> need (or can) read from the input. But I don't know what "splitting
> up" and "un-escaping" means ; could you give some practical examples
> of these?
Let's say that we have a form with two fields. One called 'name' and the
other called 'project'.
[html]
[body]
[form action="/cgi-bin/myCgi" method="GET"]
[input type="text" name="user" /][br /]
[input type="text" name="project" /][br /]
[input type="submit" /]
[/form]
[/body]
[/html]
If I put your data in here then this is what the URL will look like
/cgi-bin/myCgi?user=Tommi+Hassinen&project=ghemical
A POST is exactly the same, but the encoded string with all the
parameters is passed to stdin instead of being part of the URL.
The encoding of the parameters is as follows:
- %xx means a % sign followed by the ascii hex digits
- %xx is used to encode characters that could
cause problems with parsing
- spaces get turned into either '+' or '%20'
depending upon the browser
- the &, % and = get encoded, plus others
Here is some Perl code to detect the difference on the server:
$request_method = $ENV{'REQUEST_METHOD'};
if ($request_method eq "GET") {
$query_string = $ENV{'QUERY_STRING'};
} elsif ($request_method eq "POST") {
read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
} else {
&return_error (500, "Server Error",
"Server uses unsupported method");
}
In our case, the ServerError stuff actually means command-line
arguments.
Once you have the query string you need to split it up.
@key_value_pairs = split (/&/, $query_string);
foreach $key_value (@key_value_pairs) {
($key, $value) = split (/=/, $key_value);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
This says ... split everything at the & signs.
Then, split on the first '=' sign
Then, translate all '+' characters to spaces
Then, replace %xx with the character equiv
(where both x'es are valid hex digits)
Here are a few documents to read:
http://www.oreilly.com/openbook/cgi/ch04_02.html
http://www.oreilly.com/openbook/cgi/ch04_03.html
http://www.perlfect.com/articles/url_decoding.shtml
*** IF YOU DON'T LIKE READING PERL ***
Here is some c source code to do exactly the same thing:
http://www.scit.wlv.ac.uk/~jphb/sst/c/cgisc.html
If you search the web you can find *lots* of examples.
Miguel
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Jmol-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jmol-developers