POSTing from a perl script to web server

  • Thread starter mozilla.bugzilla
  • Start date
M

mozilla.bugzilla

hi, there

I am a newer to perl. I am trying to write a perl program to
automaticlly submite the form to the webserver.

here is the original html source code,

<form name="ecomm_frm" method="post" action="process.aspx?c=us&amp"
id="ecomm_frm">
<input type="hidden" name="EVENTTARGET" value="EditView:OptOutButton"
/>
<input type="hidden" name="EVENTARGUMENT" value="" />
<input type="hidden" name="VIEWSTATE" value="dDwxMDcyMzE"/>
<script language='javascript'>
<!--
function doPostBack(eventTarget, eventArgument) {
var theform = document.forms['ecomm_frm'];

if( theform == null )
{
//-- Second form is not the search molecule
theform = document.forms[0];
}
theform.EVENTTARGET.value = eventTarget;
theform.EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script>
<input name="EditView:first" type="text" id="EditView_first" />
<input name="EditView:last" type="text" id="EditView_last" />
<input name="EditView:mEmail" type="text" maxlength="50"
id="EditView_mEmail" />
<a
href="javascript:doPostBack('subscriber:SubmitButton','')">Submit</a>
</form>


Following is my perl code,


////////////////////////////////////////////////
#!/usr/bin/perl

use strict;
use warnings;
use LWP 5.64;
my $browser = LWP::UserAgent->new;

my $url ='http://mywebsite.......';
my $response = $browser->post( $url,
[ EditView:first => 'mozilla',
EditView:last => 'bugzilla',
EditView:mEmail => '(e-mail address removed)',
EVENTTARGET=>'subscriber:SubmitButton',
EVENTARGUMENT=>'',
VIEWSTATE=>'dDwxMDcyMzE',
]
);

die "$url error: ", $response->status_line
unless $response->is_success;
die "Weird content type at $url -- ", $response->content_type
unless $response->content_type eq 'text/html';
print $response->content;

//////////////////////////////


when I tried to run this, the system always told me there are errors in
these 3 lines: syntax error at line 13 near "Editview". Seems that I
can not include ":" in the entity name. Would you guys help me how to
figure this out? Thanks.

EditView:first => 'mozilla',
EditView:last => 'bugzilla',
EditView:mEmail => '(e-mail address removed)',
 
A

A. Sinan Unur

(e-mail address removed) wrote in @z14g2000cwz.googlegroups.com:
#!/usr/bin/perl

use strict;
use warnings;

Good. Thank you very much.
use LWP 5.64;
my $browser = LWP::UserAgent->new;

my $url ='http://mywebsite.......';
my $response = $browser->post( $url,
[ EditView:first => 'mozilla',
EditView:last => 'bugzilla',
EditView:mEmail => '(e-mail address removed)',
....

when I tried to run this, the system always told me there are errors
in these 3 lines: syntax error at line 13 near "Editview".

'EditView:first' => 'mozilla',
'EditView:last' => 'bugzilla',
'EditView:mEmail' => '(e-mail address removed)',

Sinan
 
P

Paul Lalli

my $response = $browser->post( $url,
[ EditView:first => 'mozilla',
EditView:last => 'bugzilla',
EditView:mEmail => '(e-mail address removed)',
EVENTTARGET=>'subscriber:SubmitButton',
EVENTARGUMENT=>'',
VIEWSTATE=>'dDwxMDcyMzE',
]
when I tried to run this, the system always told me there are errors in
these 3 lines: syntax error at line 13 near "Editview". Seems that I
can not include ":" in the entity name. Would you guys help me how to
figure this out? Thanks.

EditView:first => 'mozilla',
EditView:last => 'bugzilla',
EditView:mEmail => '(e-mail address removed)',

The problem here is that the => operator isn't quite magical enough.
The => is defined as a "special" comma. It is special in that it will
automatically quote its left operand *if and only if* that left operand
is a "bareword". A bareword is defined as a sequence of one or more
alpha-numeric characters. If the sequence contains anything else (such
as a colon), it is not a bareword, and the => therefore does not
automatically quote it. You are forced to quote it manually:

'EditView:first' => 'mozilla',
'EditView:last' => 'bugzilla',
'EditView:mEmail' => '(e-mail address removed)',

You can read more about the => operator in
perldoc perlop

Hope this helps,
Paul Lalli
 
T

Tad McClellan

Paul Lalli said:
(e-mail address removed) wrote:
The problem here is that the => operator isn't quite magical enough.
The => is defined as a "special" comma. It is special in that it will
automatically quote its left operand *if and only if* that left operand
is a "bareword".


There is an even further restriction (from perldata.pod):

It is often more readable to use the C<< => >> operator between key/value
pairs. The C<< => >> operator is mostly just a more visually distinctive
synonym for a comma, but it also arranges for its left-hand operand to be
interpreted as a string--if it's a bareword that would be a legal identifier.


So, => will autoquote its left operand when that operand matches:

/^[a-z_]\w*$/i

A bareword is defined as a sequence of one or more
alpha-numeric characters.


If you had said "can be thought of" instead of "defined as", you
would have been OK. :)

From perldata.pod again:

A word that has no other interpretation in the grammar will
be treated as if it were a quoted string. These are known as
"barewords".
 
P

Paul Lalli

Tad said:
If you had said "can be thought of" instead of "defined as", you
would have been OK. :)

Fair enough. I'll try to be less precise in the future. :p

Paul Lalli
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top