SOAP::Lite can't connect to host
Yesterday I tried to do a script that sends data to a website but I encountered a strange error that I solved:
I installed this perl modules with windows cmd(not in order):
cpanm MIME::Base64
cpanm MIME::Parser
cpanm MIME::Tools
cpanm Test::XML
cpanm SOAP::Lite
cpanm SOAP::WSDL
cpan App::cpanminus
This was my old script (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;
And I encountered this error (that I solved):
Service description 'http://itorrents.org/api/torrage.wsdl' can't be loaded: 500 Can't connect to itorrents.org:443
I solved by downloading the torrage.wsdl from http://itorrents.org/api/torrage.wsdl and I replaced this line (of old caching.pl script):
$infoHash = SOAP::Lite->service( 'http://itorrents.org/api/torrage.wsdl' )->cacheTorrent( $tor );
With this line (instead of the torrage.wsdl located in the website I tried replacing it with my pc path of where the torrage.wsdl file that I downloaded was):
$infoHash = SOAP::Lite->service( 'C:\Users\sussq\Desktop\perl2exe\torrage.wsdl' )->cacheTorrent( $tor );
But now i encounter this error:
Service description 'C:\Users\sussq\Desktop\perl2exe\torrage.wsdl' can't be loaded: 501 Protocol scheme 'c' is not supported
Can anyone know how to solve this? Thanks in advance.
Solution 1:
The definition of the service()
method that you call is given in the documentation for SOAP::Lite as:
service(service URL)
$client->service('http://svc.perl.org/Svc.wsdl');
So the argument that you need to pass into the method is a URL - the address of the WSDL file.
Initially, you pass it the URL - http://itorrents.org/api/torrage.wsdl. But for some reason that doesn't work (from your answer, it seems you've got to the bottom of that problem).
So you saved the WSDL file locally and passed the location of the local file to the method. That doesn't work as 'C:\Users\sussq\Desktop\perl2exe\torrage.wsdl' is not a valid URL.
The first part of a URL (the bit before the colon) is the 'protocol'. That means it defines the mechanism used to retrieve this resource. In a web-based URL, that's either 'http' or 'https'. The local path that you try to pass to the method rates with 'c:', so the method thinks that's a protocol. But it's not one that it knows about, so you get your error message.
There is a mechanism for building URLs to local files. It's called the file: protocol. I'm no expert on Windows, but I think your URL should be:
file:///C:/Users/sussq/Desktop/perl2exe/torrage.wsdl
Solution 2:
A URI is expected, and
C:\Users\sussq\Desktop\perl2exe\torrage.wsdl
isn't one. One could use
file:///C:/Users/sussq/Desktop/perl2exe/torrage.wsdl
But what if we didn't want to hardcode an absolute path? We could use the following:
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;
This would look for torrage.wsdl
in the same directory as the script.