POSTing from a perl script to web server

Discussion in 'Perl Misc' started by mozilla.bugzilla@gmail.com, Jul 8, 2005.

  1. Guest

    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 => '',
    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 => '',
     
    , Jul 8, 2005
    #1
    1. Advertising

  2. wrote in news:1120822018.028426.212100
    @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 => '',


    ....

    > 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' => '',

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Jul 8, 2005
    #2
    1. Advertising

  3. Paul Lalli Guest

    wrote:
    > my $response = $browser->post( $url,
    > [ EditView:first => 'mozilla',
    > EditView:last => 'bugzilla',
    > EditView:mEmail => '',
    > EVENTTARGET=>'subscriber:SubmitButton',
    > EVENTARGUMENT=>'',
    > VIEWSTATE=>'dDwxMDcyMzE',
    > ]

    <snip>
    > 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 => '',


    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' => '',

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

    Hope this helps,
    Paul Lalli
     
    Paul Lalli, Jul 8, 2005
    #3
  4. Paul Lalli <> wrote:
    > wrote:


    >> EditView:last => 'bugzilla',


    > 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".


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jul 8, 2005
    #4
  5. Paul Lalli Guest

    Tad McClellan wrote:
    > Paul Lalli <> wrote:
    > > 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. :)
    >


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

    Paul Lalli
     
    Paul Lalli, Jul 8, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,860
  2. alanb
    Replies:
    2
    Views:
    574
    alanb
    Apr 23, 2004
  3. AmitKu
    Replies:
    7
    Views:
    582
    John Timney \(MVP\)
    Jan 8, 2007
  4. pj
    Replies:
    3
    Views:
    321
  5. kath
    Replies:
    4
    Views:
    804
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page