Why does this jQuery.post not work with Perl CGI?

I am trying to understand why I do not see params with $ .post ("/ url /", {wtf: 2}).

I use this perl:

use strict;
use CGI;

my $cgi = new CGI;
print $cgi->header("text/javascript");
print "'no'";

use Data::Dumper;
warn Dumper({ (map {$_=>$cgi->param($_ )} $cgi->param), postdata=>$cgi->param("POSTDATA") });

When I output $ .get ("/ url", {wtf: 2}), I get the expected results and find wtf equal to 2 in the logs. When I use $ .post ("/ url /", {wtf: 2}), I don’t see any parameters at all (just $ VAR1 = {postdata => undef} in the logs).

What am I missing?

Firebug shows that: Transfer-Encoding is "chunked" and Content-Type is "application / x-www-form-urlencoded; charset = UTF-8". In addition, the Mail tab displays the arguments in the request, but there is no joy from the CGI.

+3
source share
3

Linux-, "nc" (netcat) 80 , .

, . , Apache ? , .

+2

, /x -www-form-urlencoded, multipart/form-data. CGI doc :

POSTed application/x-www-form-urlencoded multipart/form-data, POSTed , - POSTDATA. , :

    my $data = $query->param('POSTDATA');
+4

, CGI:: Lite.

Turns off the .post function in jquery, it seems to override the type of form content, even if it was explicitly set. A simple "ngrep" showed that it always goes through:

application/x-www-form-urlencoded; charset=UTF-8 

The problem was that the CGI :: Lite module only expected an exact match to "application / x-www-form-urlencoded" (i.e. without a character set bit).

Changing this line of code from an exact match to matching a regular expression in CGI / Lite.pm helped me:

#($content_type eq 'application/x-www-form-urlencoded')) {
($content_type =~  /application\/x-www-form-urlencoded/)) {
+1
source

Source: https://habr.com/ru/post/1703778/


All Articles