Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

how to add a refer to LWP::UserAgent

by coldfingertips (Pilgrim)
on May 22, 2006 at 19:04 UTC ( [id://551008]=perlquestion: print w/replies, xml ) Need Help??

coldfingertips has asked for the wisdom of the Perl Monks concerning the following question:

I read a post on how to fake an HTTP referer but that was for WWW::Mechanze and I'm working with LWP::UserAgent.

I came across this code

$ua->default_header('Accept-Language' => "no, en");
So I am thinking that it can be done through here, but what would I use? ua->default_header('Referer' => "test"); , ua->default_header('referer' => "test");, ua->default_header('Refer' => "test"); , ua->default_header('refer' => "test"); , etc.

Thanks everyone.

Replies are listed 'Best First'.
Re: how to add a refer to LWP::UserAgent
by sulfericacid (Deacon) on May 22, 2006 at 19:21 UTC
    You were right the first time.
    $ua->default_header('Referer' => "");

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

Re: how to add a refer to LWP::UserAgent
by gellyfish (Monsignor) on May 22, 2006 at 19:22 UTC

    You can set the Referer in the HTTP::Request object:

    use HTTP::Request; use LWP::UserAgent; + my $agent = LWP::UserAgent->new(); + my $req = HTTP::Request->new(GET => 'http://localhost' ); + $req->referer('http://localhost/'); + my $response = $agent->request($req);


Re: how to add a refer to LWP::UserAgent
by BigRare (Pilgrim) on May 22, 2006 at 19:27 UTC
    It would go something along the lines of this:
    # Create a user agent object use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->agent("ima User Agent"); # Create a request my $req = HTTP::Request->new(GET => ''); $req->header(Accept => "text/html, */*;q=0.1", referer => 'http://ww; # 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; } else { print $res->status_line, "\n"; }
Re: how to add a refer to LWP::UserAgent
by Joost (Canon) on May 22, 2006 at 19:23 UTC
Re: how to add a refer to LWP::UserAgent
by ww (Archbishop) on May 22, 2006 at 19:32 UTC
    or, without the tact (at least as I understood it) displayed by Joost: re "faking...."

    OK, I can think of legit reasons but I can also think of lots of blackhattery, chapeau-noir, etc for which this information might be potentially used.

    update Fletch and Joost make valid points below. Guess that all that's left in defense (and it needs it) of this observation is my belief that many||most web aps are VERY poorly secured. So while I agree with Fletch's assessment of blame, I don't think that's the end of the chain of victims -- clueless users, like my Grandparent or yours, wanna-be-webmasters who haven't had the exposure to the school of hardknocks that some||many monks have endured (and profitted from) and so on... ie, the very folk to whom Joost 's phrase --- "good security measures..." --- is a complete mystery.

      Anyone whose web application is compromised because they trusted the contents of the referrer header has only themselves to blame.

      Haha. Well, I just wasn't thinking straight (for some reason I kept substituting "location" for "referer")

      Actually, I can't really think of any good security measures that can be messed with by faking referer headers. The few times I've had to fake them myself was for automating really badly "secured" web apps. Usually all you'll mess up are website statistics - which are unreliable anyway.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://551008]
Approved by Joost
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (1)
As of 2024-07-21 21:51 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.