in reply to LWP get Cookies for API
You don't tell us where your approach fails and how.
Simply converting your curl command line to LWP::UserAgent using curl2lwp gives:
#!perl use strict; use warnings; use WWW::Mechanize; use HTTP::Request; my $ua = WWW::Mechanize->new(); my $r = HTTP::Request->new( 'GET' => 'https://example.com/', [ 'Accept' => '*/*', 'Accept' => 'application/json', 'Authorization' => '<token>', 'Host' => 'example.com:443', 'User-Agent' => 'curl/7.55.1', ], ); my $res = $ua->request( $r, ); __END__ Created from curl command line curl -X GET "https://example.com" -H "accept: application/json" -H "au +thorization:<token>"
If your question is how to extract the cookie from a browser request, have a look at the response you see in the browser.
If your question is how to extract the cookie automatically without involving a browser, first you need to find out what request you have to make to which URL, and also whether sending the username and password as a JSON string in a POST request is the correct approach there. If that is correct, then instead of inspecting the responseContent, inspect the response headers using $response->headers->as_string().
You already mention a variable suggestively named $cookies, but you never pass it anywhere. See the ->cookie_jar method of LWP::UserAgent on how to set a cookie jar for LWP::UserAgent.
|
|---|