There are a few things that I would change. First,
my $latin2 = find_encoding("iso-8859-2");
I'd change that to
my $enc = find_encoding("iso-8859-2")->name;
That's because I hate to type:). You could do similarly with
my $userAgent = LWP::USerAgent->new;
I'd do
my $ua = LWP::UserAgent->new;
Then, to debug the script, I'd use something like Debug::STDERR. I put it in the script.
#!/usr/bin/perl use strict; use warnings; use Encode; use Getopt::Long; use HTML::Form; use HTTP::Request::Common; use LWP::UserAgent; use URI::Escape::JavaScript; BEGIN { $ENV{DEBUG} = 1; } use Debug::STDERR; my $url; my $message = ''; my $scripts = ''; my $username; my $password; my $file; my $name; my $login = 0; my $response; my $usage = "usage: upload.pl url [--message] [--scripts] [--username --password] +[--file [--name]]"; GetOptions( 'message|m=s' => \$message, 'scripts|s=s' => \$scripts, 'username|u=s' => \$username, 'password|p=s' => \$password, 'file|f=s' => \$file, 'name|a=s' => \$name ) or die $usage; if ( @ARGV != 1 ) { die $usage } $url = $ARGV[0]; if ( $username && $password ) { $login = 1; } elsif ( $username || $password ) { die 'Username and password must be supplied together.'; } if ($file) { if ( !-e $file ) { die "File not found: $file" } } elsif ( !$message ) { die 'Either a file or a message must be supplied +.' } my $ua = LWP::UserAgent->new; debug( my_debug => { ua => $ua } ); $ua->agent('PerlKamion'); $ua->cookie_jar( {} ); my $enc = find_encoding("iso-8859-2"); #login if ($login) { print "Logging in...\n"; $response = $ua->post( 'http://lohere.net/_user/bejelentkezes.php?login=true', [ user => $username, password => $password ], Content_Type => 'form_data', ); if ( $response->filename == "bejelentkezes.php" ) { $enc->decode( $response->content ) =~ m|<font color="red">(.+?)</font>|; die "Unable to log in: $1"; } } # authentication print "Authenticating...\n"; $response = $ua->get($url); $enc->decode( $response->content ) =~ m|unescape\('(.+?)'\)|; my @forms = HTML::Form->parse( js_unescape($1), $url ); # upload my %uploadForm = $forms[0]->form; $uploadForm{'longcat'} = $scripts; $uploadForm{'is'} = $message; if ($file) { $uploadForm{'looong'} = [ $file, $name ] } print "Posting...\n"; $response = $ua->post( $url, \%uploadForm, Content_Type => 'form-data' + ); my $responseText = $enc->decode( $response->content ); print $responseText; if ( index( $responseText, "Oldal friss\u00edt\u00e9se..." ) == -1 ) { $responseText =~ m|<td align="left">(.+?)</td>|; die "Upload error: $1"; } print "Done.";
Update: Fixed encoding error.

In reply to Re: Decode stops working by Khen1950fx
in thread Decode stops working by vahokif

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.