SOAP::Lite 无法连接到主机

SOAP::Lite can't connect to host

昨天我尝试做一个脚本将数据发送到网站但是我遇到了一个奇怪的错误 I solved:

我用 windows 命令安装了这个 perl 模块(不按顺序):

cpanm MIME::Base64
cpanm MIME::Parser
cpanm MIME::Tools
cpanm Test::XML
cpanm SOAP::Lite
cpanm SOAP::WSDL
cpan App::cpanminus

这是我的旧脚本 (caching.pl):

#!/usr/bin/perl

use MIME::Base64 ();

use SOAP::Lite ();

open( FILE, 'my.torrent' ) or die "$!";

while( read( FILE, $buf, 60*57 ) ) { $tor .= MIME::Base64::encode( $buf ); }
close( FILE );

$infoHash = SOAP::Lite->service( 'http://itorrents.org/api/torrage.wsdl' )->cacheTorrent( $tor );

print $infoHash;

我遇到了这个错误(我解决了):

Service description 'http://itorrents.org/api/torrage.wsdl' can't be loaded: 500 Can't connect to itorrents.org:443

我通过从 http://itorrents.org/api/torrage.wsdl 下载 torrage.wsdl 并替换了这一行(旧的 caching.pl 脚本):

$infoHash = SOAP::Lite->service( 'http://itorrents.org/api/torrage.wsdl' )->cacheTorrent( $tor );

使用此行(而不是网站中的 torrage.wsdl,我尝试将其替换为我下载的 torrage.wsdl 文件所在的电脑路径):

$infoHash = SOAP::Lite->service( 'C:\Users\sussq\Desktop\perl2exe\torrage.wsdl' )->cacheTorrent( $tor );

但是现在我遇到了这个错误:

Service description 'C:\Users\sussq\Desktop\perl2exe\torrage.wsdl' can't be loaded: 501 Protocol scheme 'c' is not supported

有谁知道怎么解决的吗?提前致谢。

您调用的 service() 方法的定义在 the documentation for SOAP::Lite 中给出为:

service(service URL)

$client->service('http://svc.perl.org/Svc.wsdl');

所以您需要传递给方法的参数是 URL - WSDL 文件的地址。

最初,您将 URL - http://itorrents.org/api/torrage.wsdl 传递给它。但由于某种原因,这不起作用(从你的回答来看,你似乎已经找到了问题的根源)。

因此您将 WSDL 文件保存在本地并将本地文件的位置传递给该方法。这不起作用,因为 'C:\Users\sussq\Desktop\perl2exe\torrage.wsdl' 不是有效的 URL.

URL 的第一部分(冒号前的位)是 'protocol'。这意味着它定义了用于检索此资源的机制。在 web-based URL 中,它是 'http' 或 'https'。您尝试传递给方法的本地路径使用 'c:',因此该方法认为这是一个协议。但它不是它所知道的,因此您会收到错误消息。

有一种将 URLs 构建到本地文件的机制。它被称为 file: 协议。我不是 Windows 方面的专家,但我认为您的 URL 应该是:

file:///C:/Users/sussq/Desktop/perl2exe/torrage.wsdl

需要一个 URI,并且

C:\Users\sussq\Desktop\perl2exe\torrage.wsdl

不是一个。可以使用

file:///C:/Users/sussq/Desktop/perl2exe/torrage.wsdl

但是如果我们不想硬编码绝对路径呢?我们可以使用以下内容:

use Cwd       qw( abs_path );
use FindBin   qw( $RealBin );
use URI::file qw( );

my $uri = URI::file->new( abs_path( "$RealBin/torrage.wsdl" ) )->as_string;

这将在与脚本相同的目录中查找 torrage.wsdl