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

查看:29
本文介绍了如何使用 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,但是这样您就失去了 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.

POSTDATA 技巧记录在优秀的 CGI.pm 文档中 此处.

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

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

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