示例代码:
sub record_put :Private {
my ( $self, $c, @args ) = @_;
$c->log->info( join ', ', %{ $c->request->headers } ) ;
$c->log->info( $c->request->body ) ;
$c->response->body( $c->request->body ) ;
}
这是日志数据:
[info] user-agent, Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.71 Chrome/28.0.1500.71 Safari/537.36, connection, keep-alive, accept, application/json, text/javascript, */*; q=0.01, accept-language, en-US,en;q=0.8, x-requested-with, XMLHttpRequest, origin, http://localhost:3000, accept-encoding, gzip,deflate,sdch, content-length, 125, host, localhost:3000, ::std_case, HASH(0xaec0ba0), content-type, application/json, referer, http://localhost:3000/test
[info] /tmp/PM2C6FXpcC
以下是文档中的一段文本Catalyst::Request
:
$req->body
Returns the message body of the request, as returned by HTTP::Body: a string, unless Content-Type is application/x-www-form-urlencoded, text/xml, or multipart/form-data, in which case a File::Temp object is returned.
File::Temp
手册页没有帮助。即使“对象”重载了它的字符串化,我也看不到如何提取内容。