Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I would like to post the xml file via LWP and I am getting a failure response from the server as 'file is not submitted'.
#!/perl/bin/perl use HTTP::Request::Common qw(POST); use LWP::UserAgent; my $ua = new LWP::UserAgent; my $req = POST 'http://someprivatesite.com/getfile.cgi', [ "./some.xml",'xml_file','Content-type' => 'multipart/form-data' +]; my $res = $ua->request($req); print $res->as_string;
Above code constantly gives me failure. If I try the 'html form' provided and submit via browser, it works fine.

Thanks for your help

Replies are listed 'Best First'.
Re: Uploading a file via LWP
by pizza_milkshake (Monk) on May 01, 2004 at 00:00 UTC
    i got this to work just fine on one of my image-uploading galleries. i think you've simply formatted your data structure incorrectly. the documentation is a bit confusing as it mentions the structure you use and then the one i used. nonetheless, seems to work.
    #!perl -wl use strict; use HTTP::Request::Common qw(POST); use LWP::UserAgent; use Data::Dumper; my $ua = LWP::UserAgent->new; my $req = POST( "http://parseerror.com/images/" ,"Content_Type" => "form-data" ,"Content" => [ "image_file" => [ "uploadme.gif" ] ] ); my $res = $ua->request($req); print $res->as_string;

    perl -e'$_="nwdd\x7F^n\x7Flm{{llql0}qs\x14";s/./chr(ord$&^30)/ge;print'

      Great. It worked like a charm.!! Many thanks to you..