The response I get to an LWP request is application/x-www-form-urlencoded
is it possible convert the text of this to a hash via some object method?
问问题
1750 次
1 回答
8
# from a HTTP::Response object
my $urlencoded = $response->content;
Vars
inCGI
返回一个哈希值。use CGI qw(); CGI->new($urlencoded)->Vars;
parameters
inPlack::Request
返回一个Hash::MultiValue
对象,它实际上是适合此的数据结构。use Plack::Request qw(); Plack::Request->new({QUERY_STRING => $urlencoded})->parameters;
param
inAPR::Request
/libapreq2
- 不完全是 Perl 哈希,而是带有附加 Magic 的 XS 对象,其行为足够接近。insert hand-waving here, no libapreq2 available right now for testing
-
require URL::Encode::XS; use URL::Encode qw(url_params_mixed); url_params_mixed $urlencoded;
parse_query_string
在CGI::Deurl::XS
use CGI::Deurl::XS 'parse_query_string'; parse_query_string $urlencoded;
query_form
在URI
紧要关头,in 也很好用;query_form_hash
在URI::QueryParam
. _use URI qw(); URI->new("?$urlencoded")->query_form; use URI::QueryParam qw(); URI->new("?$urlencoded")->query_form_hash;
奖励:另请参见Catalyst
HTTP::Body::UrlEncoded
使用的。
于 2012-03-13T19:44:23.063 回答