Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:05:01+00:00 2026-06-18T06:05:01+00:00

How to load cookies from file in Mojo like this code: my $mech =

  • 0

How to load cookies from file in Mojo like this code:

my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());

if (-e "cookie.txt") {
    print q[Cookie file: cookie.txt found!\n];

    $mech->cookie_jar(HTTP::Cookies->new(
        file => q[cookie.txt],
    ));

    $mech->get(qq[$cfg->{'url'}/login]) or die qq[invalid request\n];
} else {
    print q[Cookie file: cookie.txt NOT found!\n];

    $mech->get(qq[$cfg->{'url'}/login]) or die qq[invalid request\n];

    $mech->submit_form(
        form_name => 'login',
        fields => {
            'email'     => $cfg->{'email'},
            'password'  => $cfg->{'password'},
        },
    );
    die qq[ERROR: Failed to login!\n] unless ($mech->success);

    $mech->cookie_jar->save("cookie.txt");
}

Unless there cookie.txt, the script uses the username and password, and the resulting cookies saved in the file cookie.txt and the next time using this file.

I’m trying to rewrite this code without using Mechanize and i have a problem with saving and loading a cookie file.

my $ua = Mojo::UserAgent->new;
$ua->cookie_jar(Mojo::CookieJar->new);
and then I do not know how to continue :)

P.S. Sorry for my english and perl 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:05:02+00:00Added an answer on June 18, 2026 at 6:05 am

    As I know, Mojolicious does not support this feature, but you can use store and retrive functions of the Storable module this way:

    use Mojo::Base -strict;
    
    # uncomment to be sure
    #BEGIN { $ENV{MOJO_USERAGENT_DEBUG} = 1; }
    
    use Mojo::UserAgent;
    use Storable;
    
    my $cookie_path = 'my.cookie';
    my $req_str     = 'http://www.google.com/';
    
    
    SAVE: {
      my $ua1 = Mojo::UserAgent->new;
      $ua1->get($req_str);
      store $ua1->cookie_jar, $cookie_path;
    }
    
    my $ua2 = Mojo::UserAgent->new;
    
    # load
    $ua2->cookie_jar(retrieve($cookie_path));
    
    # make a request with loaded cookie
    $ua2->get($req_str);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page http://www.sample.com/load.html ,which loads javscript file http://example.com/test.js which contains code for
I am using this code: def req(url, postfields): proxy_support = urllib2.ProxyHandler({http : 127.0.0.1:8118}) opener
So one of my co-workers used the following code to remove the cookies from
When I try to install WWW::Mechanize distribution from CPAN with strawberry perl ( v5.10.1)
How can I make a post request using cookies from php. My php code:
I found several solutions for creating Flash LSOs from JavaScript (for example: http://www.nuff-respec.com/technology/cross-browser-cookies-with-flash )
here is my code <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html xmlns=http://www.w3.org/1999/xhtml xmlns:fb=http://www.facebook.com/2008/fbml>
load.js: jQuery(document).ready(function($) { $('.dialog ul li').click(function(e) { switch($(this).attr('id')) { case 'addProject': $('.addDialog').load('/add/addprojectform'); break; case
I load a webpage from my assets in a webview. Now i need to
I'm trying to store all cookies that I get from a website and than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.