我的网络非常糟糕。我想调整XML :: LibXML的连接超时有办法吗?还是我需要先用LWP加载html?
mymap
答案 0 :(得分:2)
我个人会使用Mojo::UserAgent:
#!/usr/bin/env perl
use strict;
use warnings;
use Mojo::UserAgent;
use XML::LibXML;
my $url = "https://www.w3schools.com/xml/cd_catalog.xml";
my $ua = Mojo::UserAgent->new();
$ua->max_redirects(0)->connect_timeout(3)->request_timeout(5);
my $xml = $ua->get( $url )->result->body;
my $doc = XML::LibXML->load_xml( string => $xml );
print $doc->toString();