'field2' => [{'subfield1' => 'x', 'subfield2' => 'y'}, possibly more in array],

See HTTP::Request::Common, LWP doesn't accept/process hash refs , it doesn't have a concept of "subfields", like a regular html form its just key/value pairs. Specifically LWP* wants a flat list like this

[ 'field1' => '1', 'field2{subfield1]' => 'x', 'field2[subfield2]' => 'y', 'field3{subfield3]' => 'int', 'field3{subfield4}' => 'string', ]

What you're looking for is like the opposite of CGI::Struct , it is PHP::HTTPBuildQuery / http_build_query

update: An example of a round trip with PHP::ParseStr/php_parse_str :)

update: and now with "LWP"

#!/usr/bin/perl -- use strict; use warnings; use PHP::HTTPBuildQuery qw/ http_build_query /; use PHP::ParseStr qw( php_parse_str ); use Data::Dump qw/ dd /; use WWW::Mechanize; my $con = { 'field1' => '1', 'field2' => [ { 'subfield1' => 'x', 'subfield2' => 'y' }, ], 'field3' => { subfield3 => 'int', 'subfield4' => 'string' }, }; my $hbq = http_build_query($con); my $pps = php_parse_str($hbq); dd( $con, $hbq, $pps ); my $ua = WWW::Mechanize->new( autocheck => 0 ); $ua->timeout(0.1); $ua->add_handler("request_send", sub { shift->dump; return }); #~ $ua->add_handler("response_done", sub { shift->dump; return }); #~ $ua->show_progress(1); $ua->post( 'http://localhost/', Content => $hbq, ); $ua->post( 'http://localhost/', Content => [ "field1" => 1, "field2[0][subfield1]" => "x", "field2[0][subfield2]" => "y", "field3[subfield3]" => "int", "field3[subfield4]" => "string", ], ); __END__ ( { field1 => 1, field2 => [{ subfield1 => "x", subfield2 => "y" }], field3 => { subfield3 => "int", subfield4 => "string" }, }, "field1=1&field2%5B0%5D%5Bsubfield2%5D=y&field2%5B0%5D%5Bsubfield1%5 +D=x&field3%5Bsubfield3%5D=int&field3%5Bsubfield4%5D=string", { field1 => 1, field2 => [{ subfield1 => "x", subfield2 => "y" }], field3 => { subfield3 => "int", subfield4 => "string" }, }, ) POST http://localhost/ Accept-Encoding: gzip User-Agent: WWW-Mechanize/1.73 Content-Length: 125 Content-Type: application/x-www-form-urlencoded field1=1&field2%5B0%5D%5Bsubfield2%5D=y&field2%5B0%5D%5Bsubfield1%5D=x +&field3%5Bsubfield3%5D=int&field3%5Bsubfield4%5D=string POST http://localhost/ Accept-Encoding: gzip User-Agent: WWW-Mechanize/1.73 Content-Length: 125 Content-Type: application/x-www-form-urlencoded field1=1&field2%5B0%5D%5Bsubfield1%5D=x&field2%5B0%5D%5Bsubfield2%5D=y +&field3%5Bsubfield3%5D=int&field3%5Bsubfield4%5D=string

In reply to Re: LWP::UserAgent POST pass hash ( PHP::HTTPBuildQuery http_build_query ) by beech
in thread LWP::UserAgent POST pass hash by Stoney2005

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.