use HTTP::Request::Common Problem when Updating with String

S

Sure

Hello All,
I want to update a form using the LWP & HTTP method. It was
working fine when I am updating the values like this

$ua = LWP::UserAgent->new;
$url ='http://xxx.be/cgi-bin/viewauth/Tracking/TestProjectAgainInitialDevStory#edittable2';
use HTTP::Request::Common;

my $res = $ua->request(POST $url,
Content_Type =>'form-data',
Content => [
ettablenr => '2',
etcell2x1 =>'Task',
etcell2x2 =>'2',
etcell2x3 =>'3',
etcell2x4 =>'4',
etcell2x5 =>'High',
etcell2x6 =>'SureshC',
etcell2x7 =>'CSuresh',
etcell2x8 =>'Twiki Data Updation',
etrows => '2',
etsave =>'Save table']);


It was not working when I store the value into a Variable. Like This.

$postStr = ettablenr => '2', etcell2x1 =>'Task', etcell2x2 =>'2',
etcell2x3 =>'3', etcell2x4 =>'4', etcell2x5 =>'High', etcell2x6
=>'SureshC', etcell2x7 =>'CSuresh', etcell2x8 =>'Twiki Data
Updation', etrows => '2', etsave =>'Save table']);

$ua = LWP::UserAgent->new;
my $res = $ua->request(POST $url, Content_Type=>'form-data', Content
=>[$postStr]);

Can any one pls let me know what is the problem when i doing like
this.


Thanks in Advance
 
J

Jim Gibson

Sure said:
Hello All,
I want to update a form using the LWP & HTTP method. It was
working fine when I am updating the values like this

Disclaimer: I have not used LWP, but I can see a possible problem with
your code.
$ua = LWP::UserAgent->new;
$url
='http://xxx.be/cgi-bin/viewauth/Tracking/TestProjectAgainInitialDevStory#edit
table2';
use HTTP::Request::Common;

my $res = $ua->request(POST $url,
Content_Type =>'form-data',
Content => [
ettablenr => '2',
etcell2x1 =>'Task',
etcell2x2 =>'2',
etcell2x3 =>'3',
etcell2x4 =>'4',
etcell2x5 =>'High',
etcell2x6 =>'SureshC',
etcell2x7 =>'CSuresh',
etcell2x8 =>'Twiki Data Updation',
etrows => '2',
etsave =>'Save table']);

So request() expects a reference to an array following Content.
It was not working when I store the value into a Variable. Like This.

$postStr = ettablenr => '2', etcell2x1 =>'Task', etcell2x2 =>'2',
etcell2x3 =>'3', etcell2x4 =>'4', etcell2x5 =>'High', etcell2x6
=>'SureshC', etcell2x7 =>'CSuresh', etcell2x8 =>'Twiki Data
Updation', etrows => '2', etsave =>'Save table']);

This contains a syntax error and will not compile. I presume you mean
$postStr = [ ... ];

$postStr is a scalar variable containing a reference to an anonymous
array. Please cut-and-paste code rather than retyping it.
$ua = LWP::UserAgent->new;
my $res = $ua->request(POST $url, Content_Type=>'form-data', Content
=>[$postStr]);

You are passing Content => [ $postStr ] to request(). In other words,
you are passing a reference to an anonymous array with one element: a
reference to an anonymous array. You have one too many levels of
reference. Try changing this to: Content => $postStr


FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top