in reply to Re: POSTing QueryString data using LWP::UserAgent
in thread POSTing QueryString data using LWP::UserAgent

Hi,
I did follow your advice , with a little modification, and it worked , as far as passing the username and password; now the problem is that the XML data is not being passed .

Here's what i did. :
use HTTP::Request::Common; my $filetoopen = 'tp1.xml'; #XML file name my $ua = new LWP::UserAgent; my $res = $ua->request(GET 'http://2.2.2.2/receive.asp'); if ($res->is_success) { { no strict 'subs'; $res = $ua->request(POST 'http://2.2.2.2/receive.asp', Content +_Type => 'form-data', Content => [ username => test, password => test, init => [$filetoopen,$filetoopen], ]); } ...rest of the code...
I keep getting an error message saying that the file is empty or invalid (I've confirmed that the file is not empty and it is in the same folder as the Perl file which is executing ) Is there something missing in the POST call ? my second question is whether instead of POSTing the XML data in a file, is it possible to post the XML data contained in a scalar variable ?

Replies are listed 'Best First'.
Re: Re: Re: POSTing QueryString data using LWP::UserAgent
by screamingeagle (Curate) on Jan 10, 2002 at 13:23 UTC
    Hi,
    I finally found the solution to my problem.Just thought that I'd share it with others...Here's how u post multipart/form-data using HTTP::Request::Common, without having to create a file containing the data (submitting the content directly ) :

    use HTTP::Request::Common; my $ua = new LWP::UserAgent; my $res = $ua->request(GET 'http://2.2.2.2/page.asp'); if ($res->is_success) { { no strict 'subs'; $res = $ua->request(POST 'http://2.2.2.2/page.asp', Content_Type => 'form-data', Content => [ username => test, password => test, init => [undef, "filename", content_type => 'text/xml', content => $request_xml,], ] ); } ...
    Hope this helps someone... :)