Doing what I said seems to work to me
#!/usr/bin/perl --
use strict;
use warnings;
use WWW::Mechanize 1.73;
my $ua = WWW::Mechanize->new;
$ua->timeout(0.1);
$ua->add_handler("request_send", sub { shift->dump; return });
$ua->add_handler("response_done", sub { shift->dump; return });
$ua->show_progress(1);
$ua->put_multi(
'http://localhost',
Content_Type => 'multipart/form-data',
Content => [
fileuploadfieldname => [
undef, # filename_to_read or none in this case
"filenamesent",
-content => 'i sent you some content named filenamesent'
],
],
);
sub WWW::Mechanize::put_multi {
my( $self, $uri, @parameters ) = @_;
$uri = $uri->url if ref($uri) eq 'WWW::Mechanize::Link';
$uri = $self->base
? URI->new_abs( $uri, $self->base )
: URI->new( $uri );
unshift @parameters, $uri->as_string;
require HTTP::Request::Common;
my @suff = $self->_process_colonic_headers(\@parameters,1);
my $req = HTTP::Request::Common::POST(
@parameters,
);
$req->method('PUT');
return $self->request( $req, @suff );
}
__END__
$ perl lwp-mechanize-put-multipart-form.pl
** PUT http://localhost ==> PUT http://localhost
Accept-Encoding: gzip
User-Agent: WWW-Mechanize/1.73
Content-Length: 163
Content-Type: multipart/form-data; boundary=xYzZY
--xYzZY\r
Content-Disposition: form-data; name="fileuploadfieldname"; filename="
+filenamesent"\r
-Content: i sent you some content named filenamesent\r
\r
\r
--xYzZY--\r\n
500 Can't connect to localhost:80
Content-Type: text/plain
Client-Date: Thu, 02 Apr 2015 08:49:31 GMT
Client-Warning: Internal response
Can't connect to localhost:80\n
No connection could be made because the target machine actively refuse
+d it. at .../site/lib/LWP/Protocol/http.pm line 49.\n
500 Can't connect to localhost:80 (1s)
Error PUTing http://localhost: Can't connect to localhost:80 at lwp-me
+chanize-put-multipart-form.pl line 62.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.