in reply to Re^4: Post using LWP useragent curl post request to useragent request
in thread Post using LWP useragent curl post request to useragent request

not sure if LWP::Useragent will fetch the file contain itself

Yes, it will. Try

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use JSON; use FindBin qw($Bin);; my $token = ''; my $url = 'http://'; my $attributes = encode_json ({ name => "test.txt", parent => { id => 0 } }); my $ua = LWP::UserAgent->new; my $response = $ua->post($url, Content_Type => 'form-data', Authorization => "Bearer $token", Content => [ attributes => $attributes, file => [ "$Bin/test.txt" ], ], ); if ($response->is_success) { print $response->decoded_content; } else { die $response->status_line; }
poj
  • Comment on Re^5: Post using LWP useragent curl post request to useragent request
  • Download Code

Replies are listed 'Best First'.
Re^6: Post using LWP useragent curl post request to useragent request
by smarthacker67 (Beadle) on May 26, 2018 at 21:31 UTC
    OMG it works like charm. I still dont know why I was complicating the things. This code block works perfectly for me. Thanks you so much @poj I got stuck for like couple of days on this issue. Now I am good to go ahead its part of CPAN module I am creating. once again thanks for your help.