Maybe you're looking for https://metacpan.org/pod/Mojo::UserAgent#cookie_jar
Use one global UserAgent object for all queries - define it outside doLogin (now you're creating a new one in the doLogin sub and it dies just after result is returned)
All,

Please forgive the potentially easy answer...but it is escaping me at the moment. I have to deal with a stupid form-based Auth mechanism in order to access an internal service (SPARQL endpoint).

I have written the code necessary to extract the cookie once I send the login info to the right URL...But, in order to do follow-on queries, I need to add the resulting cookie to the header of the POST that I send back.

How do I do this?  My sub to grab the cookie is here...

my $h = 'someHost.com';

say doLogin($h,'user','pass');


sub doLogin {
    my ($host,$user,$pass) = @_;
    my $loginUrl = 'https://'.$host.'/dologinCmd.html';
    my $ua = Mojo::UserAgent->new;
my $tx = $ua->post($loginUrl => 'form' => {'httpd_username' => $user, 'httpd_password' => $pass}); if(defined $tx->res->content->headers->{'headers'}->{'location'}->[0]->[0] and $tx->res->content->headers->{'headers'}->{'location'}->[0]->[0] eq '/success.html') { return @{$tx->res->content->headers->{'headers'}->{'set-cookie'}[0]};
    }
    return 'error';
}
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to