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


In reply to Re^3: CGI Input with Escaped Characters by Anonymous Monk
in thread CGI Input with Escaped Characters by hoyt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.