Stoney2005 has asked for the wisdom of the Perl Monks concerning the following question:
For testing I also added inmy $type = 'post'; my $url = redacted; my $headers = { 'Content' => { 'field1' => '1', 'field2' => [{'subfield1' => 'x', 'subfield2' => 'y'}, possibly mo +re in array], 'field3' => {subfield3 => int, 'subfield4' => 'string'}, }, } my $response = $ua->$type( $url, %{$headers} );
I get an error back and it looks like my hash reference and array ref for field2 and field3 and passed as strings not the underlying objects so the _content string looks like The foo part parses correctly which tells me that LWP or HTTP::Request::Common POST doesn't like converting the hashes.$headers->{Content}->{'foo'} = ['bar', 'baz']
Obviously this isn't what I want. Now previously I had solved this by doing horrible things with strings."field3": "HASH(0x2308c10)"
That was in a different revision of the remote server when it wanted things in a data structure variable. Essentially I was crafting my own string _content string and passing it in. The server understood it but it was a ugly way of doing it. I'm looking for a solution that doesn't involve me having to construct the string myself$args = {data => $args}; my @newstring; foreach my $key (keys %{$args}) { foreach my $value (keys %{$args->{$key}}) { push @newstring, $key.'['.$value.']='.$args->{$key}->{$value}; } } $args = join('&',@newstring); my $response = $ua->post( $url, Content => $args );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: LWP::UserAgent POST pass hash ( PHP::HTTPBuildQuery http_build_query )
by beech (Parson) on Mar 04, 2016 at 23:16 UTC | |
by Stoney2005 (Acolyte) on Mar 07, 2016 at 12:59 UTC |