-1

我想获得有关如何发布特定网址和检索内容的解决方案。perl 可以吗?让它成为一个我们正在搜索一个特定 id 的网站,我们应该获得标记到该 id 的相关信息。

4

1 回答 1

2

用这个

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;

my $server_endpoint = "";

# set custom HTTP request header fields
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('content-type' => 'application/json');


my $resp = $ua->request($req);
if ($resp->is_success) {
    my $message = $resp->decoded_content;
    print "Received reply: $message\n";
}
else {
    print "HTTP GET error code: ", $resp->code, "\n";
    print "HTTP GET error message: ", $resp->message, "\n";
}

或者你也可以使用LWP::Simple这样做

use strict;
use warnings;
use LWP::Simple;

my $url = 'http://www.example.com';
my $content = get $url or die "Unable to get $url\n";
print $content;
于 2013-10-09T09:38:02.277 回答