develooper Front page | perl.libwww | Postings from October 2001

HTTP::Cookies rejects cookies from host a.b for domain .a.b

Thread Next
Alexandre Duret-Lutz
October 11, 2001 14:33
HTTP::Cookies rejects cookies from host a.b for domain .a.b
Message ID:
Hi people,

I'm writing an HTTP client for SourceForge using LWP (libwww-perl 5.53).

I need to login to SourceForge by POSTing a form, to get an
identification cookie before further processing.

The trouble is that the (queried) host '' sends me a
cookie as follow:

Set-Cookie: username=BLABLABLA; expires=Wed, 17-Oct-01 22:37:23 GMT; path=/;

and HTTP::Cookies reject it with the this debug output:

HTTP::Cookies::extract_cookies: Domain does not match host

I have no idea who is right, it's the first time I work with
cookies.  (Reading RFC 2109 I'd vote for HTTP::Cookies, however
other browsers seems to accept these cookies just fine.)

I've modified my copy of as follow to get around this.

@@ -322,7 +322,8 @@
 	# Check domain
 	my $domain  = delete $hash{domain};
-	if (defined($domain) && $domain ne $req_host) {
+	if (defined($domain)
+	    && $domain ne $req_host && $domain ne ".$req_host") {
 	    if ($domain !~ /\./ && $domain ne "local") {
 	        LWP::Debug::debug("Domain $domain contains no dot");
 		next SET_COOKIE;

For completeness, the code I am using is as follow (it's a reconstruction):

    &LWP::Debug::level ('+debug');
    my $ua = new LWP::UserAgent;
    $ua->cookie_jar (new HTTP::Cookies 
                     file => $cookie_jar, 
                     autosave => 1);
    my $req = POST ("",
                    [form_loginname => $login,
                     form_pw        => $passwd,
                     stay_in_ssl    => 1,
                     login          => "Login With SSL"]);
    my $res = $agent->request ($req);

Alexandre Duret-Lutz

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About