Created
May 27, 2015 06:27
-
-
Save xlat/216c510d1600d68b8bd4 to your computer and use it in GitHub Desktop.
Reproduce a matter of decoding parameter from a post query.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use utf8; #script encoded in utf8 without bom | |
use Mojolicious::Lite; | |
use Data::HexDump; | |
{ | |
require Mojolicious; | |
say "perl $^V, Mojolicious: v", Mojolicious->VERSION, ", ", `chcp` ; | |
} | |
post '/' => sub{ | |
my $self = shift; | |
my $params = $self->req->params->to_hash; | |
app->log->debug("received data:\n", HexDump( $params->{a} ) ); | |
use Devel::Peek; | |
Dump( $params->{a} ); | |
$self->render( text => "ok for '$params->{a}'" ); | |
}; | |
if(my $pid = fork()){ | |
use Mojo::UserAgent; | |
my $t = Mojo::UserAgent->new; | |
#simulate front-end query | |
my $tx = $t->post('http://127.0.0.1:3042/' => | |
{ 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' }, | |
form => { a => 'été'} | |
); | |
my $res = $tx->res->body; | |
say "result:\n", HexDump($res); | |
use Devel::Peek; | |
Dump( $res ); | |
kill 'SIGKILL', $pid; | |
exit(0); | |
} | |
app->start(qw(daemon --listen http://*:3042 )); |
Everything is okay with that script (but the use of Data::HexDump).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script output is as follow:
I can't figure out why server received a string [UTF8 "\x{e9}t\x{e9}"].