How can I get the entire request body with CGI.pm?

前端 未结 3 1075
臣服心动
臣服心动 2020-12-10 11:30

I\'m trying to write a Perl CGI script to handle XML-RPC requests, in which an XML document is sent as the body of an HTTP POST request.

The CGI.pm module does a gr

3条回答
  •  春和景丽
    2020-12-10 12:11

    To handle all cases, including those when Content-Type is multipart/form-data, read (and put back) the raw data, before CGI does.

    use strict;
    use warnings;
    
    use IO::Handle;
    use IO::Scalar;
    
    STDIN->blocking(1); # ensure to read everything
    my $cgi_raw = '';
    
    { 
      local $/; 
      $cgi_raw = ;
      my $s;
      tie  *STDIN, 'IO::Scalar', \$s;
      print STDIN $cgi_raw;
      tied(*STDIN)->setpos(0);
    }
    
    use CGI qw /:standard/;
    ...
    

提交回复
热议问题