Perl Mechanize by submitting a form with a file (image)?

I can’t find a good example of how to do it properly, the ones I found do not work for me .. I am trying to submit a form using perl mechanize, where the form has an image file, the form below is actually a way. by which I am trying to access this API for the website from which I have an account, and using POST is apparently the easiest way to use their API:

<HTML>
<BODY>

<form 
 method="post" 
 name="image_upload"
 action="http://example-website.com" 
 enctype="multipart/form-data">
 <input type="hidden" name="field1"  value="">
 <input type="text"   name="username"  value="">
 <input type="text"   name="password"  value="">
 <input type="file"   name="pict">
 <input type="text"   name="field2"   value="0">
 <input type="text"   name="field3" value="0">
 <input type="submit" value="Send">
</form>

</BODY>
</HTML>

I tried this, but its not loading the image file, it seems .. any advice is welcome. (I just left parts of the script, but I can submit other forms using this method, and not the ones that require a file upload)

fill form field:
$mech->form_name('image_upload');

$mech->set_fields( field1 => '', 
username => $username,
password => $password,
pict => '/home/user1/Desktop/pic.jpg',
field2 => '0',
field3 => '0'
);

#### submit form
$mech->submit();
+3
1

autocheck => 1 $mech, .

print $mech->content $mech->submit,

, , :

$mech->agent_alias( 'Windows IE 6' )

, , cookie , . ( , cookie )

+1

Source: https://habr.com/ru/post/1754061/


All Articles