A
A
Alexander Skipped2014-09-07 23:43:03
Perl
Alexander Skipped, 2014-09-07 23:43:03

How to send a file in the body of a POST request in Perl?

To form a request, I use the HTTP::Request::Common module.
I need the data from the file to be sent not as part of the form, but in the body of the request. This is how CURL is sent when called.
curl 'URL' --data-binary FILE
This doesn't work for me.

my $request = POST $self->{url}, Content   => [ $params->{file} ];

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
s1dney, 2014-09-08
@s1dney

Try Content-Type: to put the appropriate one.

P
pcdesign, 2014-09-11
@pcdesign

If I understand the question correctly, then:

my $req = POST  $self->{url},
                   Content_Type => 'form-data',
                   Content      => 
                   [
                     $params->{file} => [ /tmp/file.name ], 
                   ];

M
mazxcv, 2014-10-07
@mazxcv

try this
$ua->post($url, Content_Type => "form-data", Content => ['upload[]' => ['/tmp/file.name']])->res->body;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question