Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting cookies from a Mojolicious user agent response
    primarykey
    data
    text
    <p>I started using the Mojolicious library for testing and everything was working fine in until I tried to extract cookies from a response.</p> <p>I've tried several variants of:</p> <pre><code>$ua = Mojo::UserAgent-&gt;new(); $ua-&gt;on( error =&gt; sub { my ($ua, $error) = @_; say "This looks bad: $error"; } ); $ua-&gt;max_redirects(1)-&gt;connect_timeout(10)-&gt;request_timeout(20); $ua-&gt;cookie_jar(Mojo::CookieJar-&gt;new); # ... later ... my $tx = $ua-&gt;get($url); my $jar = $ua-&gt;cookie_jar-&gt;extract($tx); # This is undef </code></pre> <p>I can however extract the cookies via LWP::UserAgent. However, LWP has several different issues that make that option unworkable for now. Just for a comparison here is the LWP code that does extract the cookies.</p> <pre><code>my $lwp = LWP::UserAgent-&gt;new(cookie_jar =&gt; {}, timeout =&gt; 20, max_redirect =&gt; 1); push @{ $lwp-&gt;requests_redirectable }, 'POST'; my $response = $lwp-&gt;get($url); die $response-&gt;status_line unless $response-&gt;is_success; $lwp-&gt;cookie_jar-&gt;scan(\&amp;ScanCookies); sub ScanCookies { my ($version, $key, $value) = @_; say "$key = $value"; } </code></pre> <p>So I know that I have the $url etc. correct.</p> <p>Edit: I should mention that i'm using strawberry 5.14</p> <p>Edit2: I should also mention that the cookies are getting into the user agent for sure, because the session ID is getting handled properly. Unfortunately, I have a need to access another cookie (for testing the site) and I just don't seem to be able the get the right incantation to access them... saying that I believe this to be a programmer problem and nothing more.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload