in reply to Re^2: CGI Input with Escaped Characters
in thread CGI Input with Escaped Characters

Hi,

You forgot to escape  {"request":{"service":"test"},"data":{"test_input":"%2B2"}}

This is an error  CGI->new( 'data={"request":{"service":"test"},"data":{"test_input":"%2B2"}}' );

You want this  CGI->new( 'data=%7B%22request%22%3A%7B%22service%22%3A%22test%22%7D%2C%22data%22%3A%7B%22test_input%22%3A%22%252B2%22%7D%7D')

You want this  CGI->new( { data => $actual_data, } )

Its like writing

my $query = CGI->new({}); $query->param( 'data', $actual_data ); print $query->self_url;

This is how query-string/form-data works

Now if you were to use HTTP POST/PUT/PATCH you could use raw json in the request ; they call that AJAX

{ use LWP; my $req = HTTP::Request->new( POST => 'http://127.0.0.1:80/' ); $req->content_type( 'application/json' ); #~ $req->header('X-File-Name' => 'tiny.gif' ); $req->content_length( length $actual_data ); $req->content( $actual_data ); print "\n", $req->as_string, "\n"; } __END__ POST http://127.0.0.1:80/ Content-Length: 59 Content-Type: application/json {"request":{"service":"test"},"data":{"test_input":"%2B2"}}

And to get at this ajax request from a .cgi you'd use

use CGI 4.35; my $raw_data = CGI->new->param('POSTDATA'); # or PUTDATA or PATCHDATA

An "fundvanced" example Mojolicious::Lite +and jQuery +AJAX + Mojo::Template