I am trying to automate some web browsing for testing and I need to include cookies for a particular URL (I'm obfuscating the URLs intentionally - this code will not run as is). I have researched the use of LWP::UserAgent and HTTP::Cookies and it seems rather straightforward. I am directing my script to a proxy to grab the output via Fiddler (127.0.0.1:8888). When I view my request, I do not see the cookie information included. Thoughts?

#!c:\perl\bin -w # Uses use strict; use HTTP::Request::Common qw(GET POST); use HTTP::Cookies; use LWP::UserAgent; #Globals my $response; # URL my $url = 'http://www.someurl.com'; # User Agent Object my $ua = LWP::UserAgent->new; $ua->proxy(['http', 'https'], 'http://127.0.0.1:8888'); $ua->agent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KH +TML, like Gecko) Chrome/37.0.2062.124 Safari/537.36'); # Set cookies my $cookie_jar = HTTP::Cookies->new( autosave=>'true', ignore_discard= +>'true' ); $cookie_jar->set_cookie(0,'__ibxt','dXRrXzU0MjRiMjc4NWQ2MjYxLjA5NjQyMj +A0','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'__uvst','5409ce8fb5a7a5787a65c95ca76ee4b9', +'/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'__uvstr','d9b4984a7ad2bfee5fabe70a9c25819a' +,'/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'__utmc','1','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'__uvt','','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'_bt_id.BT-22382467-3.d389','b5822f6f5d11758 +4.1411691130.1.1411691169.1411691130.','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'_mkto_trk','id:273-CKQ-053&token:_mch.com-1 +411691127927-21192','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'access_token','4e92a468ae3d022d72d177f4b018 +333131a904ab','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'jwplayer.volume','90','/','',80,0,0,86400,0 +); $cookie_jar->set_cookie(0,'ki_r','','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'lastLoggedInDate','09%2F25%2F14','/','',80, +0,0,86400,0); $cookie_jar->set_cookie(0,'locale','en_US','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'optimizelyEndUserId','oeu1411691125629r0.67 +0045307604596','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'optimizelySegments','%7B%22306102099%22%3A% +22gc%22%2C%22306155008%22%3A%22direct%22%2C%22306161004%22%3A%22false +%22%7D','/','',80,0,0,86400,0); $cookie_jar->set_cookie(0,'PHPSESSID','dtdfb3b4v8vm16uml1ro7lf38ktu6ot +e','/','',80,0,0,86400,0); $ua->cookie_jar($cookie_jar); # Request my $request = GET $url; $request->referer('https://www.xxxx.com/blah/blah/'); #$cookie_jar->add_cookie_header( $request ); $response = $ua->request($request); open OUTPUT, '>c:\output.txt' or die "Couldn't open file $!"; if ($response->is_success) { print $response->decoded_content; print OUTPUT $response->decoded_content; } else { print STDERR $response->status_line, "\n"; } close OUTPUT;

In reply to LWP::UserAgent does not send Cookies by CodeVixen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.