0

LWP を使用してフォームとして渡すことができる配列の作成に問題があります。基本コードは

my $ua = LWP::UserAgent->new();
my %form = { };
$form->{'Submit'} = '1';
$form->{'Action'} = 'check';
for (my $i=0; $i<1; $i++) {
    $form->{'file_'.($i+1)} = [ './test.txt' ];
    $form->{'desc_'.($i+1)} = '';
}

$resp = $ua->post('http://someurl/test.php', 'Content_Type' => 'multipart/form-data'
, 'Content => [ \%form ]');

if ($resp->is_success()) {
    print "OK: ", $resp->content;
}
} else {
    print $claimid->as_string;
}

test.php で _POST 変数をチェックするとき、何も設定されていないので、フォーム配列を正しく作成していないか、間違った型を使用していると思います:(

4

1 に答える 1

0

問題は、何らかの理由でフォームの値を一重引用符で囲んだことです。データ構造を送信したい。例えば:

$resp = $ua->post('http://someurl/test.php', 
                  'Content_Type' => 'multipart/form-data',
                  'Content'      => \%form);

%form, not the has reference contained within an array reference as you had ([ \%form ] [ %form ]`のハッシュ参照を送信して、ハッシュ). If you had wanted to send the data as an array reference, then you'd just useからのキーと値のペアを配列に入力します。

HTTP::Request::Common のドキュメント、特にこれを行うためのよりクリーンな方法については、 POST セクションを読むことをお勧めします。

于 2011-06-30T14:37:40.117 に答える