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

前端 未结 3 1080
臣服心动
臣服心动 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 11:59

    Right, one could use POSTDATA, but that only works if the request Content-Type has not been set to 'multipart/form-data'.

    If it is set to 'multipart/form-data', CGI.pm does its own content processing and POSTDATA is not initialized.

    So, other options include $cgi->query_string and/or $cgi->Dump.

    The $cgi->query_string returns the contents of the POST in a GET format (param=value&...), and there doesn't seem to be a way to simply get the contents of the POST STDIN as they were passed in by the client.

    So to get the actual content of the standard input of a POST request, if modifying CGI.pm is an option for you, you could modify around line 620 to save the content of @lines somewhere in a variable, such as:

    $self->{standard_input} = join '', @lines;
    

    And then access it through $cgi->{standard_input}.

提交回复
热议问题