2

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?

4

1 回答 1

8
# from a HTTP::Response object
my $urlencoded = $response->content;
  1. VarsinCGI返回一个哈希值。

    use CGI qw();
    CGI->new($urlencoded)->Vars;
    
  2. parametersinPlack::Request返回一个Hash::MultiValue对象,它实际上是适合此的数据结构。

    use Plack::Request qw();
    Plack::Request->new({QUERY_STRING => $urlencoded})->parameters;
    
  3. paramin APR::Request/libapreq2 - 不完全是 Perl 哈希,而是带有附加 Magic 的 XS 对象,其行为足够接近。

    insert hand-waving here, no libapreq2 available right now for testing
    
  4. url_params_mixedURL::Encode

    require URL::Encode::XS;
    use URL::Encode qw(url_params_mixed);
    url_params_mixed $urlencoded;
    
  5. parse_query_stringCGI::Deurl::XS

    use CGI::Deurl::XS 'parse_query_string';
    parse_query_string $urlencoded;
    
  6. query_formURI紧要关头,in 也很好用;query_form_hashURI::QueryParam. _

    use URI qw();
    URI->new("?$urlencoded")->query_form;
    
    use URI::QueryParam qw();
    URI->new("?$urlencoded")->query_form_hash;
    
  7. 奖励:另请参见CatalystHTTP::Body::UrlEncoded使用的。

于 2012-03-13T19:44:23.063 回答