Skip to content

Instantly share code, notes, and snippets.

@xlat
Created May 27, 2015 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlat/216c510d1600d68b8bd4 to your computer and use it in GitHub Desktop.
Save xlat/216c510d1600d68b8bd4 to your computer and use it in GitHub Desktop.
Reproduce a matter of decoding parameter from a post query.
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 ));
@xlat
Copy link
Author

xlat commented May 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment