dmusulin has asked for the wisdom of the Perl Monks concerning the following question:

Dear PerlMonks,
I just begun Perl about a week ago.
I program a bit in C/C++ so im only new to Perl.

The goal of the script:
I have written a script to do basic authentication
and get a html document from a website (it's just a start of a script)

The problem:
The website want's me to accept cookies before i can
continue, so i added a cookiejar to the script so that LWP::UserAgent would accept cookies.


(i got that idea from this site: http://lwp.interglacial.com/ch11_01.htm)

But when i run the script i get the error page telling me to enable cookies in my browser so that i can continue.
What am i doing wrong?

#!/usr/local/bin/perl use strict; use warnings; use LWP; use HTML::TreeBuilder; use HTML::FormatText; use HTTP::Cookies; my $url = 'https://timetables.website.x.y.z/dir/'; my $cookie_jar = HTTP::Cookies->new(); my $browser = LWP::UserAgent->new(); $browser->cookie_jar($cookie_jar); $browser->agent('Mozilla/5.0 (compatible; MSIE 7.0; Windows N +T 6.0)'); $browser->from('my email'); $browser->protocols_allowed( ['https'] ); #User Credentials for access to the website.x.y.z realm. $browser->credentials( 'timetables.website.x.y.z:443', #website and port 'timetables.website.x.y.z', #realm 'user' => 'pass' # user credentials ); my $response = $browser->get($url); die "Error at $url\n ", $response->status_line, "\n Aborting" unless $response->is_success; print "OK", $response->content_type, " document!\n"; my $content = $response->decoded_content; my $html = new HTML::TreeBuilder; $html->parse($content); my $f = new HTML::FormatText(leftmargin => 0, rightmargin => 0); print $f->format($html);
The Error Page:
Cookies are currently disabled by your browser settings.
To access this Web site, cookies must be enabled.
Follow these directions to enable cookies (Microsoft Internet Explorer 6 or later):
In Internet Explorer, on the Tools menu, click Internet Options. Click the Privacy tab, then click Sites.
In Address of Web site, type the complete address of this Web site.
For example, http://www.microsoft.com. Then click Allow.

Thanks in advance

UPDATE: Thanks for the reactions so far.
I turned off javascript and i didn't get a warning page.

im now going to diagnose the problem with live headers in FF (thanks for the tip)

Replies are listed 'Best First'.
Re: The Cookiejar Problem
by Anonymous Monk on Aug 04, 2008 at 10:33 UTC
    What am i doing wrong?
    You've stopped diagnosing the problem. To start, add to your program
    use Data::Dumper; print Dumper($response), "\n";
    or
    print "\n----\nHEADERS ", __FILE__, " SENT\n"; print $response->request->headers->as_string; print "\n----\nHEADERS ", __FILE__, " RECIEVED FROM ", $response->requ +est->uri, "\n"; print $response->headers->as_string, "\n----\n";
    and examine the output.

    If you don't see any "cookie" lines, then maybe $url is using client-side scripting (such as JavaScript) to set cookies, or your proxy (if you have one) is stripping cookies ...
    Next step would be to compare headers to those you see when using Firefox with the Live HTTP Headers plugin

Re: The Cookiejar Problem
by Gangabass (Vicar) on Aug 04, 2008 at 10:46 UTC

    I'm sure this is Javascript cookies.

    To test it you can disable Javascript in your browser and try to load page again.

    But Javascript it's not a problem. You can emulate it. Just look into Javascript, find how it works and repeat HTTP requests from your script. May be you need to store cookies manually (from script).