Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect with LWP/PERL 2

Status
Not open for further replies.

DavidJohnson

Programmer
Aug 6, 2002
7
DE
Hi all!

First of Im new to perl/cgi and I've just
started to do some tiny apps. Now I have
run in to a problem.

I want to be able to redirect my request (using LWP) to
another domainname with e.g., certain headers and datas.

I manage to do request to other domains but when I end it still is where I started. Attached below is an example of what I have done ... I want the request to stay at the url(secure_url) not be where the request from... A redirect but I haven't found out how to do it in LWP...


Thx for the help!
John


my $request = new HTTP::Request GET;
$request->url($secure_url);
$request->header("Referer" => $requested_from);
my $agent = new LWP::UserAgent;
my $response = $agent->request( $request );
print $response->content;

 
I think LWP is mainly intended to act as a web client. In order to get your users browser to automatically forward to another page, you can use the CGI module.

Clipped from the CGI.pm docs,

Code:
   print $query->redirect('[URL unfurl="true"]http://somewhere.else/in/movie/land');[/URL]
Sometimes you don't want to produce a document yourself, but simply redirect the browser elsewhere, perhaps choosing a URL based on the time of day or the identity of the user.

The redirect() function redirects the browser to a different URL. If you use redirection like this, you should not print out a header as well.

One hint I can offer is that relative links may not work correctly when you generate a redirection to another document on your site. This is due to a well-intentioned optimization that some servers use. The solution to this is to use the full URL (including the http: part) of the document you are redirecting to.

You can also use named arguments:
Code:
    print $query->redirect(-uri=>'[URL unfurl="true"]http://somewhere.else/in/movie/land',[/URL]
                           -nph=>1);
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thx goBoating!

That explains why I haven't been able to find any function/support for this in LWP.

So can I do like this if I want my own
"referer" added to the redirect (?) :


print $query->redirect(-uri=> $secure_url>,
-Referer=> $requested_from);


Again thx for your help!
"John"
 
I don't know. I would have to play with it to see ( or read the docs). Maybe you can beat me to it. If not, I'll try to get back sometime today or tomorrow. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Setting the referer when trying to redirect is pretty much impossible since it's the clients job to set the referer and to actually redirect. The referer should be the page that redirected, unless the user has turned off referers (only possible in Opera, I think). //Daniel
 
Oki, Thx.

I've read the CGI.pm docs and I didn't find any parameters
to set the referer for redirect() :(

So I start to get the picture, it seems it's impossible.

But why should it be so hard to make a request to an url with certain datas, headers and simply stay at that url??

I mean LWP can do all but not stay at the same url as the request is sent to....


Anyway, thx very much guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top