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;
VarsinCGI返回一个哈希值。use CGI qw(); CGI->new($urlencoded)->Vars;parametersinPlack::Request返回一个Hash::MultiValue对象,它实际上是适合此的数据结构。use Plack::Request qw(); Plack::Request->new({QUERY_STRING => $urlencoded})->parameters;paraminAPR::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::XSuse 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 回答