LWP::UserAgent

LWP::UserAgent

am 09.05.2005 22:49:44 von cternai

Using the LWP::UserAgents Html::Header Object doesnt work for me.

I'am not sure why.


I used it the following ways:
$ua->default_header('Referer' => "http://www.domain.de");
$ua->default_headers->push_header('Referer' => "http://www.domain.de");

used it like a html::header
$ua->default_headers->referer("http://www.domain.de");

It returns:
Can't locate object method "default_headers" via package
"LWP::UserAgent" (perhaps you forgot to load "LWP::UserAgent"?) at
../myperl.pl line 150.


No, I included LWP.

use LWP;

I already tried with

use LWP::UserAgent;

No changes.





This is what CPAN says:

$ua->default_headers( $headers_obj )

Get/set the headers object that will provide default header values for
any requests sent. By default this will be an empty HTTP::Headers
object. Example:

$ua->default_headers->push_header('Accept-Language' => "no, en");

$ua->default_header( $field )
$ua->default_header( $field => $value )

This is just a short-cut for $ua->default_headers->header( $field =>
$value ). Example:

$ua->default_header('Accept-Language' => "no, en");




thx

similian

Re: LWP::UserAgent

am 14.05.2005 22:33:56 von Janwillem Borleffs

cternai wrote:
> Using the LWP::UserAgents Html::Header Object doesnt work for me.
>

Based upon the information from the LWP perldoc page:

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

# Create a request
my $req = HTTP::Request->new(GET => 'http://somehost.nl/');
$req->header('Referer', 'http://localhost');

# Pass request to the user agent and get a response back
my $res = $ua->request($req);

# Check the outcome of the response
if ($res->is_success) {
print $res->content;
}


JW