Uploading a file usign LWP

=?iso-8859-1?Q?Emmanuel_Par=E9?= (emman@voxtel.com)
Thu, 6 Apr 2000 16:02:15 -0400


------=_NextPart_000_005C_01BF9FE1.7A4EB620
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I try to send a hidden variable that contain a file to an other server. =
=3D
but I dunno how you could do this.  Any help will be appreciated..  =3D
please email at ep@linux-mandrake.com thanks in advance for your =3D
precious help and sorry for my english..

use HTTP::Request;
use LWP::UserAgent;
use URI::Escape;

# -- Open the file containing the LM data to post.
open(LMDATA, "$ARGV[0]") || die "Could not open $ARGV[0].";

# -- Read the data, build the URL-escaped string to POST.
# -- Each line is of the form attribute=3D3Dvalue.
$postString =3D3D "";
$postString =3D3D $postString . "filename=3D3Dfile2" . "&";
$postString =3D3D $postString . "DEBUG=3D3D1" . "&";
while (<LMDATA>) {
        chomp;
        $postString =3D3D $postString . uri_escape($_) . "&";
        $DEBUG && print ("postString =3D3D $postString\n");
}
close(LMDATA);
=3D20
# -- There will be an extra & at the end; get rid of it.
chop($postString);
=3D20
$request =3D3D new HTTP::Request 'POST', $ARGV[1];
$request->header('Content-type' =3D3D> =3D
'application/x-www-form-urlencoded');
$request->header('Content-length' =3D3D> length($postString));
$request->content($postString);

ua =3D3D new LWP::UserAgent;
$response =3D3D $ua->request($request);

if ($response->is_success() && !$response->content()) {
        $DEBUG && print "success\n";
} else {
        $DEBUG && print "unsuccessful\n";
        $message =3D3D "LM barfed.\nresponse =3D3D " . =3D
$response->as_string() .
"\ncontent =3D3D " . $response->content . "\n";
        die $message
}




------=_NextPart_000_005C_01BF9FE1.7A4EB620
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
I try to send a hidden variable that contain a file = to an=20 other server. =3D
but I dunno how you could do this.  Any help = will be=20 appreciated..  =3D
please email at ep@linux-mandrake.com thanks = in advance=20 for your =3D
precious help and sorry for my english..

use=20 HTTP::Request;
use LWP::UserAgent;
use URI::Escape;

# -- = Open the=20 file containing the LM data to post.
open(LMDATA, "$ARGV[0]") || die = "Could=20 not open $ARGV[0].";

# -- Read the data, build the URL-escaped = string to=20 POST.
# -- Each line is of the form = attribute=3D3Dvalue.
$postString =3D3D=20 "";
$postString =3D3D $postString . "filename=3D3Dfile2" .=20 "&";
$postString =3D3D $postString . "DEBUG=3D3D1" . = "&";
while=20 (<LMDATA>) {
       =20 chomp;
        $postString =3D3D = $postString=20 . uri_escape($_) . = "&";
        $DEBUG=20 && print ("postString =3D3D=20 $postString\n");
}
close(LMDATA);
=3D20
# -- There will be = an extra=20 & at the end; get rid of = it.
chop($postString);
=3D20
$request =3D3D=20 new HTTP::Request 'POST', = $ARGV[1];
$request->header('Content-type'=20 =3D3D>=20 =3D
'application/x-www-form-urlencoded');
$request->header('Cont= ent-length'=20 =3D3D> = length($postString));
$request->content($postString);

ua=20 =3D3D new LWP::UserAgent;
$response =3D3D = $ua->request($request);

if=20 ($response->is_success() && !$response->content())=20 {
        $DEBUG && print=20 "success\n";
} else {
        = $DEBUG=20 && print = "unsuccessful\n";
       =20 $message =3D3D "LM barfed.\nresponse =3D3D " . = =3D
$response->as_string()=20 .
"\ncontent =3D3D " . $response->content .=20 "\n";
        die=20 $message
}


------=_NextPart_000_005C_01BF9FE1.7A4EB620--