Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use LWP::UserAgent;
- my $ua = LWP::UserAgent->new;
- my $request = HTTP::Request->new( GET => 'http://google.com/' );
- my $response = $ua->request($request);
- if ( $response->is_success and $response->previous ) {
- print $request->url, ' redirected to ', $response->request->uri, "n";
- }
- $ telnet www.google.com 80
- HEAD / HTTP/1.1
- HOST: www.google.com
- HTTP/1.1 302 Found
- Location: http://www.google.it/
- Cache-Control: private
- Content-Type: text/html; charset=UTF-8
- Set-Cookie: ##############################
- Date: Thu, 30 Oct 2008 20:03:36 GMT
- Server: ####
- Content-Length: 218
- URL url = new URL ('http://google.com')
- HttpURLConnection conn = url.openConnection()
- conn.followRedirects = false
- conn.requestMethod = 'HEAD'
- println conn.responseCode
- // Not ideal - should check response code too
- if (conn.headerFields.'Location') {
- println conn.headerFields.'Location'
- }
- 301
- ["http://www.google.com/"]
- use LWP::UserAgent;
- my $ua = LWP::UserAgent->new;
- my $request = HTTP::Request->new( GET => 'http://google.com/' );
- my $response = $ua->request($request);
- if ( $response->is_redirect ) {
- print $request->url . " redirected to location " . $response->header('Location') . "n";
- }
Add Comment
Please, Sign In to add comment