KarthikK has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I am having a webpage having the following
<input type="file" name="theFile" id="fieldFile" value="" /> <input type="submit" value="Upload" onclick="return doSubmit()" /> <script type="text/javascript"> <!-- function doSubmit() { form.submit(); } </script>

I am simulating an file upload using a PERL script. Here i was told that I have to pass the form variables 'thefile' and also the submit button value. Any idea how i could achieve this via HTTP::Request::Common? Below is my curent code and it dont seems to work
my $filename = "MyDoc.csv"; my $file = "C:\\" . $filename; $request=POST $upload_url,[ Content_Type => 'multipart/form-data', $file, $file, Content => [ 'upload' => [$file,$filename]], submit => 'Upload', Upload => 1, theFile=>$file ];
Any ideas, suggestions
Regards
Karthik

Replies are listed 'Best First'.
Re: Help required regarding HTTP::Request::Common, File upload
by Corion (Patriarch) on Apr 29, 2008 at 07:47 UTC

    The advice that you received from me back in November still applies. The advice you got in how to upload a file to a secured website? also applies.

    You still don't tell us how it "doesn't work". This is a common approach to errors, but it won't get you far, because we prefer to use your telepaths for controlling the minds of the world leaders instead of reading the minds of programmers.

    Looking at the code you post, I only see little resemblance to the code in the synopsis of HTTP::Request::Common:

    my $filename = "MyDoc.csv"; my $file = "C:\\" . $filename; $request=POST $upload_url,[ Content_Type => 'multipart/form-data', $file, $file, # what is that suppo +sed to be? Content => [ 'upload' => [$file,$filename]], # please explain thi +s line! submit => 'Upload', Upload => 1, theFile=>$file # ... and this line +too ];

    Again, you should likely use WWW::Mechanize instead, which encapsulates file uploads conveniently for you. But you were told that already.

    As a different approach, I recommend to use a network sniffer to find out the differences in what the browser sends and what your script sends. But then again, you were told that already, as well.

    A reply falls below the community's threshold of quality. You may see it by logging in.