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

Problems setting headers for a request

Thread Next
Tristan Greaves
January 17, 2001 08:55
Problems setting headers for a request
Message ID:
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?



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

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