Perl Mechanize的错误文件描述符用于文件输入

时间:2013-10-11 06:52:51

标签: perl file upload mechanize

当我尝试用文件上传字段填写表单时,我收到错误,在填写文件输入字段(bad file descriptor at ... line ...)的行处说$browser->field('some_file_field',$file) or die "$!";。我也试过普通的斜杠,脚本在windows OS下运行。

use strict;
use warnings;

use WWW::Mechanize;
use HTTP::Cookies;
use LWP::Debug qw(+);

my $user = 'user';
my $password = 'password';

my $browser = WWW::Mechanize->new(
 stack_depth => 0,
 cookie_jar      => {},
 timeout => 180,
 autocheck       => 1,
 onerror         => \&Carp::croak,);

# Login Form
my $response = $browser->get('http://somepage/de/login.php');
if (!$response->is_success) {
    die "Login page unreachable: ",  $response->status_line, "\n";
}

$browser->field('userid', $user);
$browser->field('passwd', $password);
$response = $browser->click();
if ($response->is_success) {
    print "Login Successful!\n";
} else {
    die "Login failed: ",  $response->status_line, "\n";
}

$response = $browser->get('http://somepage/import.php');
if (!$response->is_success) {
    die "Static Data Site unreachable: ",  $response->status_line, "\n";
}

my $form = $browser->form_name('importform');
$browser->select('some_select_field','test') or die "$!";
my $file = 'C:\test.txt';

$browser->field('some_file_field',$file) or die "$!";

$response = $browser->submit() or die "$!";
if ($response->is_success) {
    print "Import Successful!\n";
} else {
    die "Import failed: ",  $response->status_line, "\n";
}

0 个答案:

没有答案