owenhhs007 has asked for the wisdom of the Perl Monks concerning the following question:
I am a newbie to the Perl Programming. I'm attempting to write a Perl script that can upload a file to a web server based on the following file upload form:
<form method="post" action="/cgi-bin/luci/engineer/advanced/diagnostic +s/upgrade/"> <div class="cbi-map"> <h2><a id="content" name="content">Authorization Required</a>< +/h2> <div class="cbi-map-descr"> Please enter your username and password. </div> <fieldset class="cbi-section"><fieldset class="cbi-section-nod +e"> <div class="cbi-value"> <label class="cbi-value-title">Username</label> <div class="cbi-value-field"> <input class="cbi-input-user" type="text" name="us +ername" value="" /> </div> </div> <div class="cbi-value"> <label class="cbi-value-title">Password</label> <div class="cbi-value-field"> <input class="cbi-input-password" type="password" +name="password" /> </div> </div> </fieldset></fieldset> </div> <div> <input type="submit" value="Login" class="cbi-button cbi-butto +n-apply" /> <input type="reset" value="Clear" class="cbi-button cbi-button +-reset" /> </div> </form>
And here's my Perl code (URL, username, and password redacted):
The output says:"There is no form named"sysauth"". Can anyone tell me how to fix this? I found another thing, when I login, the source code of form changed:use LWP; use HTTP::Cookies; use WWW::Mechanize; my $userAgent = LWP::UserAgent->new(); my $request = POST 'http://192.168.1.1/cgi-bin/luci/root/advanced/diag +nostics/upgrade', Content_Type => 'multipart/form-data', Content => [ +file_0 => ['upload.zip']]; $request->authorization_basic('root', '1234'); my $response = $userAgent->request($request); print $response->error_as_HTML . "\n" if $response->is_error; my $cj = HTTP::Cookies->new( autosave => 1, ignore_discard => 1 ); my $mech = WWW::Mechanize->new( cookie_jar => $cj ); $mech->get( 'http://192.168.1.1/cgi-bin/luci/root/advanced/diagnostics +/upgrade' ); if ($mech->success()) { $mech->submit_form( form_name => 'sysauth', fields => { os_usernam +e => 'root', os_password => '1234' } ); }
A random token was generated to the URL, so maybe I need use HTTP:Cookies to keep this change, any suggestions from u, monks?<form method="post" action="/cgi-bin/luci/;stok=4DB4115975EF48FD742227 +BAD3580034/engineer/advanced/diagnostics/upgrade" enctype="multipart/ +form-data"> <table width="100%"> <tr> </tr> <tr> <td width="15%" align="right">Firmware image:</td> <td width="25%" align="left"> <input type="file" size="30" name="image" /> </td> <td width="10%"> </td> <td width="40%" align="right"> <input class="cbi-input-save" type="submit" value="Fla +sh the specified firmware file" /> </td> <td width="10%"> </td> </tr> </table> </form>
Update: I have tried another method please jump to topic:Control IE to upload file issue
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Upload Issue
by zentara (Cardinal) on Jan 12, 2010 at 15:46 UTC | |
|
Re: Upload Issue
by FloydATC (Deacon) on Jan 12, 2010 at 20:19 UTC | |
|
Re: Upload Issue
by apl (Monsignor) on Jan 12, 2010 at 15:54 UTC | |
by owenhhs007 (Initiate) on Jan 14, 2010 at 11:45 UTC | |
by owenhhs007 (Initiate) on Jan 14, 2010 at 11:46 UTC | |
|
Re: Upload Issue
by owenhhs007 (Initiate) on Jan 13, 2010 at 10:07 UTC |