in reply to how to validate lwp::useragent request?

I doubt LWP is sending anything 'wrong'. It's far more likely that the server is checking the user agent. Fortunately, LWP and related HTTP::Header and HTTP::Response objects are eminently scriptable. You can set headers to whatever you'd like.

To see all headers and values, use HTTP::Header's scan() method.

#!/usr/bin/perl use strict; use LWP::UserAgent; my $agent = LWP::UserAgent->new; my $headers = HTTP::Headers->new('User_Agent' => 'Cyberdog/5.0', 'Accept' => 'image/gif, image/x-xbitmap, image/png, image/jpeg, */*', 'Accept-Charset' => 'iso-8859-1', 'Accept-Language' => 'en-US'); #headers before the request: $headers->scan(\&printheaders); my $response = $agent -> get('http://localhost', $headers); #and after: $response->scan(\&printheaders); sub printheaders() { my $h = shift; my $v = shift; print ("Header: $h \t Value:$v\n"); }
You can clear all headers using HTTP::Headers' clear() method, but I don't think it's what you want.
--
jpg

Replies are listed 'Best First'.
Re^2: how to validate lwp::useragent request?
by ikegami (Patriarch) on Jun 07, 2005 at 22:58 UTC
    No, that's not right. Your method is not guaranteed to print all the headers. You're listing the headers too soon. For example, if you stopped overridding User-Agent, your method wouldn't list all the headers. See my post above for an explanation of why.