#!/usr/bin/env perl use WWW::Mechanize; use HTTP::CookieJar::LWP (); use IO::Socket::SSL qw(); my $uri ="https://sso.employer.com/serviceredirect/login?service=https://actualserviceurl.employer.com/my/service"; my $username = "username"; my $password = q(password); my $fields = { username => $username, password => $password, }; my $m = WWW::Mechanize->new( cookie_jar => $cookie_jar, autocheck => 1, ssl_opts => { SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, verify_hostname => 0 }, env_proxy => 1, keep_alive => 1, timeout => 30, agent => 'myagent' ); $m->max_redirect(2); my $content = $m->post($uri); $m->submit_form( form_number => 1, fields => $fields, button => 'submit' ); print $content->headers()->as_string; #### POST https://sso.employer.com/serviceredirect/login?service=https://actualserviceurl.employer.com/my/service Accept-Encoding: gzip User-Agent: myagent Content-Length: 0 Content-Type: application/x-www-form-urlencoded (no content) HTTP/1.1 200 OK [...] HTTP/1.1 302 Found Cache-Control: no-cache, no-store, max-age=0, must-revalidate Date: Fri, 22 Nov 2019 13:20:31 GMT Pragma: no-cache Via: 1.1 login.1and1.org Location: https://actualserviceurl.employer.com/my/service?ticket=xxxsuperlonggeneratedticketidxxx [...]