use LWP::UserAgent(); use HTTP::CookieJar::LWP(); ## Create browser object. my $jar = HTTP::CookieJar::LWP->new; my $ua = LWP::UserAgent->new( keep_alive=>200, cookie_jar => $jar, protocols_allowed => ['http', 'https'], timeout => 60, ); my $client='xxx.xxx.xxx.xxx'; my $username='username'; my $password'password'; my $fw_file='/home/location/file.bin'; my $xsrf=auth($client, $username, $password); ##xsrf session token is provided by separate authentication sub. my $results=upgrade($client, $fw_file); sub upgrade { ## Upload file. my ($client,$fw_file)=@_; my $res=$ua->post("http://$client/upload.cgi?xsrf=$xsrf", [ 'upfile' => ["$fw_file"], 'Submit_button' => 'Upload+Software+Image', ], Content_Type => 'form-data', ); ##Continues on to other steps from here. ##This post fails where it worked previously. }