在 Perl 中所有重定向后如何找到最终 URL? [英] How can I find the final URL after all redirections in Perl?
本文介绍了在 Perl 中所有重定向后如何找到最终 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有http://www.ritzcarlton.com",这会将我重定向到"http://www.ritzcarlton.com/en/Default.htm".Perl 有没有办法在所有重定向后找到最终 url?
Lets say I have "http://www.ritzcarlton.com" and that redirects me to "http://www.ritzcarlton.com/en/Default.htm". Is there a way in Perl to find the end url after all the redirects?
推荐答案
使用 LWP 将遵循重定向.然后,您可以查询 HTTP::Request
对象以找出它请求的 URI.
Using LWP will follow the redirections for you. You can then interrogate the HTTP::Request
object to find out the URI it requested.
use LWP::UserAgent qw();
my $ua = LWP::UserAgent->new;
my $response = $ua->get('http://www.ritzcarlton.com');
print $response->request->uri . "\n";
输出为:
http://www.ritzcarlton.com/en/Default.htm
这篇关于在 Perl 中所有重定向后如何找到最终 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文