如何使用CGI.pm获取整个请求正文? [英] How can I get the entire request body with CGI.pm?

查看:67
本文介绍了如何使用CGI.pm获取整个请求正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个Perl CGI脚本来处理XML-RPC请求,其中XML文档作为HTTP POST请求的主体发送。

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.

CGI.pm模块在从HTTP请求中提取命名参数方面做得很好,但是我不知道如何使它给我整个HTTP请求正文(即我正在处理的XML-RPC请求中的XML文档)。

The CGI.pm module does a great job at extracting named params from an HTTP request, but I can't figure out how to make it give me the entire HTTP request body (i.e. the XML document in the XML-RPC request I'm handling).

如果没有CGI.pm,是否还有另一个模块可以解析此内容信息超出要求?我希望不必从环境变量中手工提取此信息。谢谢您的帮助。

If not CGI.pm, is there another module that would be able to parse this information out of the request? I'd prefer not to have to extract this information "by hand" from the environment variables. Thanks for any help.

推荐答案

您可以使用特殊参数名称POSTDATA来获取原始POST数据。

You can get the raw POST data by using the special parameter name POSTDATA.

my $q = CGI->new;
my $xml = $q->param( 'POSTDATA' );

或者,您可以直接阅读STDIN而不是使用CGI.pm,但是随后您将失去所有其他

Alternatively, you could read STDIN directly instead of using CGI.pm, but then you lose all the other useful stuff that CGI.pm does.

优秀的CGI.pm文档此处

The POSTDATA trick is documented in the excellent CGI.pm docs here.

这篇关于如何使用CGI.pm获取整个请求正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆