abs52 has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I am trying to use LWP ( i dont mind using something else ) to do some posts and get from a website API
But i am failing at the first step.
According to their docs you need to login with your broswer, get the cookie AUTH_TOKEN and get the and then use that output for the curl command authorization. Is there way to do this in perl ?
The curl would look like
and my LWP looks likecurl -X GET "<URL> -H "accept: application/json" -H "authorization:<to +ken>"
Thanks amy $cookies = HTTP::Cookies->new(); my $ua = LWP::UserAgent->new( cookie_jar => {} ); $req -> authorization_basic ( 'cloud-bespoke' ); my $rc = REST::Client->new( { useragent => $ua } ); my $headers = {Content-type => 'application/json'}; my $client = REST::Client->new( { useragent => $ua }); my $res = $client->POST('URL', '{"username": "username, "password":"password"}', {"Content-type" => ' +application/json'}); chkerr($client->responseCode()); print $client->responseContent(); print "\n" . $cookies->as_string;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP get Cookies for API
by Corion (Patriarch) on Jun 11, 2019 at 12:17 UTC | |
|
Re: LWP get Cookies for API
by karlgoethebier (Abbot) on Jun 11, 2019 at 13:08 UTC | |
|
Re: LWP get Cookies for API
by abs52 (Novice) on Jun 11, 2019 at 13:11 UTC | |
by hippo (Archbishop) on Jun 11, 2019 at 13:23 UTC | |
by Corion (Patriarch) on Jun 11, 2019 at 13:57 UTC |