在 perl 中获取重定向的 url [英] Get redirected url in perl

查看:25
本文介绍了在 perl 中获取重定向的 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取最后一个重定向 URL.

I want to get last of redirect URL.

喜欢

url_1:http://on.fb.me/4VGeuurl_2 : https://www.facebook.com/

url_1 : http://on.fb.me/4VGeu url_2 : https://www.facebook.com/

我想在 perl 中通过 url_1 获取 url_2.以前的来源在下面.

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;
}

提前致谢.

推荐答案

您可以使用

$response->request()

您可以使用

$response->previous()

一起:

while ($response) {
   say $response->request()->uri();
   $response = $response->previous();
}

这篇关于在 perl 中获取重定向的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆