I put in a lot of time to come up with a solution on a previous occasion.
Update: Here is a module that adds a post function to Win32::IE::Mechanize.
=pod
Win32/IE/Mechanize/Post.pm
Adds function post to Win32::IE::Mechanize
if it doesn't already exist.
usage:
use Win32::IE::Mechanize::Post;
-or-
use Win32::IE::Mechanize::Post ();
The post function accepts for arguments anything
HTTP::Request::Common::POST would accept.
$ie->post('http://www.example.com/survey.cgi', [
name => 'John Doe',
email => 'doe@example.org',
gender => 'M',
born => '1976',
perc => '3%',
]);
# multipart/form-data
$ie->post('http://www.example.com/survey.cgi',
Content_Type => 'form-data',
Content => [
name => 'John Doe',
email => 'doe@example.org',
gender => 'M',
born => '1976',
init => ["$ENV{HOME}/.profile"],
],
);
=cut
use strict;
use warnings;
use Win32::IE::Mechanize qw( );
package Win32::IE::Mechanize;
use HTTP::Request::Common qw( );
use Win32::OLE::Variant ;# qw( Variant VT_* );
if (!*post{CODE}) {
*post = sub {
my $self = shift;
my $agent = $self->{agent};
local $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 0;
my $request = HTTP::Request::Common::POST( @_ );
my $uri = $request->uri;
($uri = $self->uri
? URI->new_abs( $uri, $self->uri->as_string )
: URI->new( $uri )
);
my $headers = $self->_extra_headers( $uri )
. $request->headers_as_string( "\015\012" );
$agent->navigate({
URL => $uri->as_string,
Headers => $headers,
PostData => Variant( VT_UI1, $request->content ),
});
$self->_wait_while_busy;
};
}
1;
Untested. Let me know if there are any problems.
Next step: testing it and submitting it as a patch.
|