Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Setting referer with HTTP::Request and LWP::UserAgent

by punch_card_don (Curate)
on Mar 07, 2009 at 15:21 UTC ( [id://749047]=perlquestion: print w/replies, xml ) Need Help??

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

Moonlit Monks,

My Perl script at www.anotherdomain.com/cgi-bin/bar/myscript.pl needs to redirect to an html page that is at www.mydomain.com/foo/page.htm To ensure that this page can be accessed only by a redirect from my script - I know I'll get heat for this, but bear with me - I propose to put an htaccess file in the foo directory that will accept requests only from one specific, imaginary, referer. Then, have myscript set the referer header that accompanies its redirect.

To do that, I lifted this code from here:

http://www.microsoft.com/mspress/books/sampchap/5612c.aspx

use HTTP::Request::Common qw(POST GET); use LWP::UserAgent; $ua = LWP::UserAgent->new(); $req = POST 'http://www.northwindtraders.com/dologin.asp', [ Username => 'mike', Password => 'mypa$w0rd', ]; $req->header(Referer => 'http://www.northwindtraders.com/login.html'); $res = $ua->request($req);
changing northwindtraders.com to mydomain.com

But it doesn't work for me. I get the dreaded Server Error.

Any advice on either how to make this code work, or other ways to do the same thing, would be greatly appreciated.

Thanks.




Time flies like an arrow. Fruit flies like a banana.

Replies are listed 'Best First'.
Re: Setting referer with HTTP::Request and LWP::UserAgent
by Anonymous Monk on Mar 07, 2009 at 15:37 UTC
    If all you want is a redirect, why use LWP?
    use CGI; print CGI->header( -nph =>1, -Referer => 'http://www.northwindtraders.com/login.html', -location => 'www.mydomain.com/foo/page.htm', ); __END__ HTTP/1.0 200 OK Server: cmdline Date: Sat, 07 Mar 2009 15:38:40 GMT Location: www.mydomain.com/foo/page.htm Referer: http://www.northwindtraders.com/login.html Content-Type: text/html
      That's very cool, so I put it in myscript.pl:
      #!/usr/bin/perl -w use strict; use CGI; print CGI->header( -nph =>1, -Referer => 'http://www.northwindtraders.com/login.html', -location => 'www.mydomain.com', );
      I get the exact same output from the command line - huge step forward, thanks - but surfing to the script with a browser still produces Internal Server Error.

      What am I missing?

Re: Setting referer with HTTP::Request and LWP::UserAgent
by Anonymous Monk on Mar 07, 2009 at 15:33 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-18 18:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found