Domanda

Here's section of code and i am trying to POST whole array using LWP but server is receiving only first row of array(0 index) while others are not getting sent to server, please guide what i am doing wrong

$data_post[0] = "text1";
$data_post[1] = "text2";
$data_post[2] = "texxt3";
$data_post[3] = "text4";
$data_post[4] ="text5";
my $ua= LWP::UserAgent->new();
my $response = $ua->post( $url, { 'istring' => @data_post} );

my $content  = $response->decoded_content();
my $cgi = CGI->new();
print $cgi->header(), $content;
È stato utile?

Soluzione

You can't assign an array to a hash key, only a scalar. Your attempt will expand the array and send this:

{ "istring" => "text1", "text2" => "texxt3", "text4" => "text5" }

Use an array ref instead by putting the "take a reference" operator in front of the array:

{ istring => \@data_post }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top