Search code examples
perlwordpresslwp-useragent

How to fetch exact url


Can anyone please guide about how we can get exact url and store in a string from wordpress post id eg htttp://www.domain.com/?p=444 If we visit this above postid url, it takes users to exact url http://www.domain.com/posturl/ so i need help with short lwp perl code to return this "exact url" and print it etc

any help will be really appreciated. Thanks


Solution

  • The base method from HTTP::Response will get you the absolute URI:

    #!/usr/bin/env perl
    
    use strict;
    use warnings;
    
    use LWP::UserAgent;
    
    my $lwp      = LWP::UserAgent->new;
    my $response = $lwp->get('http://www.domain.com/?p=444');
    print $response->base;