Request to send Perl to send a zip file as base64?

I have a Perl script trying to send a zip file, for example using the LWP UserAgent module

my $req = POST $url, Content_Type => 'form-data',
    Content      => [
        submit => 1,
        upfile =>  [ $fname ]
    ];

where $ fname is the path to the file. On the server side, although it seems that my POST array has only "send". Should I base64 encode the file and assign it to a variable? What is the best way to do this?

+3
source share
1 answer

Make sure the file name can be resolved. You should receive an error message if it cannot be. At least I do in my version HTTP::Request::Common.

You do not need to encode binary content as Base64. (Unless, of course, the server application does not expect this format.)

Here's the full sample script:

use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common 'POST';

my $ua = LWP::UserAgent->new;
my $url = 'http://localhost:8888'; # Fiddler
my $req = POST $url,
    Content_Type => 'form-data',
    Content => [
        submit  => 1,
        upfile  => [ 'C:\temp\bla.zip' ],
    ];
my $line = '=' x 78 . "\n";
print $line, $req->as_string;
my $rsp = $ua->request( $req );
print $line, $rsp->as_string;
+2
source

All Articles