Fetching question (this was once answered by Luke from Hong Kong)

Discussion in 'Perl Misc' started by Jeff M., Oct 18, 2004.

  1. Jeff M.

    Jeff M. Guest

    I'm trying to fetch a link and i dont need the content of the link i
    just need the link itself. Here is what i mean:
    Lets say when you go to: http://www.go.to/username it forwards you to:
    http://www.geocities.com/username

    So how do i fetch url http://www.go.to/username to find out which url
    it forwarded me to.

    Few years ago i was working with a programmer, Luke, from Hong Kong
    and he was able to figure this out for me. And now i need this again,
    Luke if you are out there please contact me.

    Thanks
    Jeff M., Oct 18, 2004
    #1
    1. Advertising

  2. Jeff M. wrote:

    > So how do i fetch url http://www.go.to/username to find out which url it
    > forwarded me to.


    I think you're searching for a HEAD-Request. This should give you the
    Response-Headers.

    g,
    Robert

    --
    http://www.dunkelheit.at/
    sapere aude.
    Robert Sedlacek, Oct 18, 2004
    #2
    1. Advertising

  3. (Jeff M.) wrote in news:c308860a.0410180743.584147c1
    @posting.google.com:

    > I'm trying to fetch a link and i dont need the content of the link i
    > just need the link itself. Here is what i mean:
    > Lets say when you go to: http://www.go.to/username it forwards you to:
    > http://www.geocities.com/username
    >
    > So how do i fetch url http://www.go.to/username to find out which url
    > it forwarded me to.
    >
    > Few years ago i was working with a programmer, Luke, from Hong Kong
    > and he was able to figure this out for me. And now i need this again,
    > Luke if you are out there please contact me.


    Use the force, Luke, use the force.

    Sorry, I could not resist.

    Anyway, check out the documentation for the LWP module. The example given
    in perldoc LWP is good enough to get you started. That is, read the
    documentation first instead of trying to locate some guy called look. The
    equivalent of the 'using the force' in programming is reading the docs.

    use strict;
    use warnings;

    use LWP::UserAgent;

    my $ua = LWP::UserAgent->new;
    $ua->agent("RedirectFinder ");

    my $req = HTTP::Request->new(HEAD => 'http://some.url.invalid');
    my $res = $ua->request($req);

    if(my $rp = $res->previous) {
    print $rp->header('Location');
    }

    __END__

    Sinan
    A. Sinan Unur, Oct 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    200
  2. tinhogor

    hong kong java programmer

    tinhogor, Aug 1, 2012, in forum: Java
    Replies:
    1
    Views:
    200
    hkpe0318
    Aug 15, 2012
  3. hkpe0318

    Re: hong kong java programmer

    hkpe0318, Aug 15, 2012, in forum: Java
    Replies:
    0
    Views:
    269
    hkpe0318
    Aug 15, 2012
  4. hkpe0318

    Re: hong kong java programmer

    hkpe0318, Aug 16, 2012, in forum: Java
    Replies:
    0
    Views:
    258
    hkpe0318
    Aug 16, 2012
  5. hkpe0318

    Re: hong kong java programmer

    hkpe0318, Aug 17, 2012, in forum: Java
    Replies:
    0
    Views:
    262
    hkpe0318
    Aug 17, 2012
Loading...

Share This Page