I need to submit a HTTP POST
request to a certain URL, and I am required to specify a parameter name that can be interpreted as an array - like this:
parameter[]=123
However, no matter what I try, LWP is always escaping [] characters.
Here is sample code:
#!/usr/bin/perl
use strict;
use warnings;
use LWP;
use HTTP::Request::Common;
$|=1;
my $ua = LWP::UserAgent->new;
my $post_url = "http://192.168.1.1/something";
my $params = { };
$params->{something} = "abc";
$params->{'array[]'} = 123;
my $response = $ua->request(POST $post_url, [ $params ]);
Data submitted looks like this:
POST /something HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Host: 192.168.1.1
User-Agent: libwww-perl/5.835
Content-Length: 29
Content-Type: application/x-www-form-urlencoded
array%5B%5D=123&something=abc
And I need it to look like this:
POST /something HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Host: 192.168.1.1
User-Agent: libwww-perl/5.835
Content-Length: 25
Content-Type: application/x-www-form-urlencoded
array[]=123&something=abc
I have no control over remote application and can not influence anything, I simply have to specify a single parameter like this (as a parameter of an array, which it really isn't), and I need to find a way how to do this, without Perl escaping bracket characters.
I have tried defining 'array'
as array
and arrayref
(and many other things), but LWP does not seem to understand the concept of array parameters, even if I have multiple values for this parameter, they will all be submitted with same parameter name (?array=123&array=456&array=789
) - so that won't work either.
Mostly, I am wondering if I can somehow (short of modifying module sources) prevent LWP to automatically escape these characters when making a POST request.
Thanks.