Hi. It's been a while since I used Perl, so this could be totally obvious, in which case I apologize. This is my script:
use strict; use Encode; use Getopt::Long; use HTML::Form; use HTTP::Request::Common; use LWP::UserAgent; use URI::Escape::JavaScript; 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 su +pplied together.' } if ($file) { if (!-e $file) { die "File not found: $file" } } elsif (!$message) { die 'Either a file or a message must be supplied.' + } my $userAgent = LWP::UserAgent->new; $userAgent->agent('PerlKamion'); $userAgent->cookie_jar( {} ); my $latin2 = find_encoding("iso-8859-2"); #login if ($login) { print "Logging in...\n"; $response = $userAgent->post('http://lohere.net/_user/bejelentkezes. +php?login=true', [ user => $username, password => $pass +word ], Content_Type => 'form_data', ); if ($response->filename == "bejelentkezes.php") { $latin2->decode($response->content) =~ m|<font color="red">(.+?) +</font>|; die "Unable to log in: $1"; } } # authentication print "Authenticating...\n"; $response = $userAgent->get($url); $latin2->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 = $userAgent->post($url, \%uploadForm, Content_Type => 'form +-data'); my $responseText = $latin2->decode($response->content); print $responseText; if (index($responseText, "Oldal frissítése...") == -1) { $responseText =~ m|<td align="left">(.+?)</td>|; die "Upload error: $1"; } print "Done.";
This works fine, until my $responseText = $latin2->decode($response->content); where decode seems to do nothing at all (the response content is misinterpreted as UTF-8, I think). Any ideas? Also, I'd appreciate it if you could point out things I'm "doing the wrong way". Thanks.

In reply to 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.