I use perl for ajax (POST method), and when I read POST query with script below, I get my query URIencoded.
Example: sent – привет , received: %D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82
Latin queries work well. Script was just googled somewhere.
Script:
sub populatePostFields {
%_POST = ();
read( STDIN, $tmpStr, $ENV{ "CONTENT_LENGTH" } );
@parts = split( /\&/, $tmpStr );
foreach $part (@parts) {
( $name, $value ) = split( /\=/, $part );
$value =~ ( s/%23/\#/g );
$value =~ ( s/%2F/\//g );
$_POST{ "$name" } = $value;
}
}
Well, it’s not Perl-specific. The web browser is required to URI-encode the values when sending.
You can use the standard
use CGImodule to decode form fields for you — this is definitely recommended, as it will take care of all kinds of edge cases for you, and is also usable if you decide to convert to amod_perlmodule later.If you’re running a CGI script, I also strongly recommend that you have
-Ton theshebangline (#!/usr/bin/perl -T) anduse strict;, to help catch things that might otherwise be easily exploitable over the web.→
You can use the
->param(string)to read the various form fields; it’ll handle GET and POST transparently, and decode the URI-encoded strings for you.The “not-recommended, hard way” would be to use the expression: