在perl中获取重定向的url [英] Get redirected url in perl
本文介绍了在perl中获取重定向的url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b url_1:
http://on.fb.me/4VGeurel =nofollow> http://on.fb.me/4VGeu
url_2: https://www.facebook.com/
我想通过perl中的url_1获取url_2。
以前的来源位于下方。
sub get_redirect_location
{
my($ url)= @_;
my $ ua = LWP :: UserAgent-> new;
$ ua-> proxy('http','SAMPLE_PROXY');
my $ req = new HTTP :: Request(GET => $ url);
my $ res = $ ua->请求($ req);
返回$ res-> headers_as_string;
}
预先致谢
解决方案
您可以使用
$ response来找到导致响应的请求 - > request()
您可以使用
$获得链中的前一个响应b$ b
$ response-> previous()
所有在一起:
while($ response){
say $ response-> request () - > URI();
$ response = $ response-> previous();
}
I want to get last of redirect URL.
like
url_1 : http://on.fb.me/4VGeu url_2 : https://www.facebook.com/
I want to get url_2 by url_1 in perl. Previous source is below.
sub get_redirect_location
{
my ($url) = @_;
my $ua = LWP::UserAgent->new;
$ua->proxy('http', 'SAMPLE_PROXY');
my $req = new HTTP::Request(GET => $url);
my $res = $ua->request($req);
return $res->headers_as_string;
}
Thanks in advance.
解决方案
You can find the request that lead to a response using
$response->request()
You can get the previous response in the chain using
$response->previous()
All together:
while ($response) {
say $response->request()->uri();
$response = $response->previous();
}
这篇关于在perl中获取重定向的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文