Simple HTTP client

#!/usr/bin/perl

# Create a user agent object

use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);

# Create a request: GET, POST, HEAD
$method = "HEAD";
my $req = new HTTP::Request $method => 'http://10.145.10.62:9000/disk/video/O0$3$27I138/00000.m2ts';

#$req->content_type('application/x-www-form-urlencoded');
#$req->content('match=www&errors=0');

$req->header( 'getcontentFeatures.dlna.org' => '1' );


# Pass request to the user agent and get a response back
my $response = $ua->request($req);

# Check the outcome of the response
if ($response->is_success) {
    print $response->status_line . "\n";
    print "Content-Type=" . $response->header( 'Content-Type' ) . "\n";
    print "Content-Length=" .  $response->header( 'Content-Length' ) . "\n";
    print "Cache-Control=" .  $response->header( 'Cache-Control' ) . "\n";
    print "contentFeatures.dlna.org="  . $response->header( 'contentFeatures.dlna.org' ) . "\n";
      #print $response->content;
  }
else {
      print STDERR $response->status_line, "\n";
  }

留言

熱門文章