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

Problems setting headers for a request

Thread Next
From:
Tristan Greaves
Date:
January 17, 2001 08:55
Subject:
Problems setting headers for a request
Message ID:
003f01c080a6$4d9a2cd0$b601010a@DCTF000J
Hi all,

The aim of the following code is to allow the HTTP headers for
a request to be set.  At the moment, it's just trying
User-Agent, but this would be extended to allow other, perhaps
custom, headers.

<--begin code fragment-->
        my $ua = LWP::UserAgent->new();
        my $req = HTTP::Request->new(GET => $url);
        $req->header(User_Agent => 'FooBarBrowser 1.0');

        # Prove that we've actually set the headers...
        print $req->headers_as_string();
        print "<---ENDHEADERS--->\n";

        # Perform request...

        my $response = $ua->request($req);
<--end code fragment-->

However, this doesn't appear to work - The User-Agent string does
not appear to be set, according to the logs at the "other end".

I'm aware of the $ua->agent() system (which works!!), but I want
to use the above method to allow custom ones to be added.

So, what's the problem?

Thanks,

Tris.

--- 
Tristan Greaves.
Argogroup, Oak House, Shackleford Road, Elstead, Surrey GU8 6LB, UK.
T: +44 (0)1252 705 782  F: +44 (0)1252 705 706  http://www.argogroup.com/ 

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About