Problems setting headers for a request

Tristan Greaves (tgreaves@argogroup.com)
Wed, 17 Jan 2001 16:55:30 -0000


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/