Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

XML::LibXML https

by agentorange (Sexton)
on Nov 29, 2013 at 17:31 UTC ( #1064995=perlquestion: print w/ replies, xml ) Need Help??
agentorange has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

Can anyone help with a simple query please? How do I get XML::LibXML to work over https? Cannot see anything in the module's docs that describes it. The WSDL is available via a browser on both http and https and has been proven.

eg: This works using http

use strict; use warnings; use XML::Compile::WSDL11; # use WSDL version 1.1 use XML::Compile::SOAP11; # use SOAP version 1.1 use XML::Compile::SOAP::WSS; use XML::Compile::Transport::SOAPHTTP; use Data::Dumper; # WSDL URL location and method my $wsdlURL = 'http://my.server.net/callback?wsdl'; my $method = 'UpdateStatus'; # Retrieve WSDL my $wsdlXML = XML::LibXML->new->parse_file($wsdlURL);
But with the protocol https it fails with "Could not create file parser context for file "https://my.server.net/callback?wsdl": No such file or directory at...
use strict; use warnings; use XML::Compile::WSDL11; # use WSDL version 1.1 use XML::Compile::SOAP11; # use SOAP version 1.1 use XML::Compile::SOAP::WSS; use XML::Compile::Transport::SOAPHTTP; use Data::Dumper; # WSDL URL location and method my $wsdlURL = 'https://my.server.net/callback?wsdl'; my $method = 'UpdateStatus'; # Retrieve WSDL my $wsdlXML = XML::LibXML->new->parse_file($wsdlURL);

Comment on XML::LibXML https
Select or Download Code
Re: XML::LibXML https
by tobyink (Abbot) on Nov 29, 2013 at 20:09 UTC

    The easy way would be to retrieve the file into a string and then parse the string as XML; for example...

    use HTTP::Tiny; my $wsdlResponse = HTTP::Tiny->new->get($wsdlURL); $wsdlResponse->{success} or die; my $wsdlXML = XML::LibXML->new->parse_file($wsdlResponse->{content});
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
      Thank you for clarifying a part I was not understanding. I am of course ultimately just retrieving a string. It's much easier to solve a problem when you understand the problem! ;o)

      With your explanation I've resolved it like so.

      # WSDL URL location and method my $wsdlURL = 'http://my.server.net/callback?wsdl'; my $method = 'UpdateStatus'; # Retrieve WSDL # # During dev ignore SSL cert errors my $ua = LWP::UserAgent->new ( ssl_opts => { verify_hostname => 0, SSL_verify_mode => 0x00 }); # Get WSDL # my $response = $ua->get( $wsdlURL ); $wsdlXML = XML::LibXML->load_xml(string => $response->content, recover + => 2 ); print Dumper $wsdlXML if $debug;
Re: XML::LibXML https (unsupported)
by Anonymous Monk on Nov 30, 2013 at 02:12 UTC

    How do I get XML::LibXML to work over https? Cannot see anything in the module's docs that describes it.

    Its because its not supported, libxml doesn't support https (nanohttp no s)

      That google link doesn't find any relevant results. Do you have a better link? And what's nanohttp?

        That google link doesn't find any relevant results.

        Yes, this is why I included it

        And what's nanohttp?

        as far as I can tell, its how libxml's http support is implemented ... no ssl or openssh anywhere in sources, only nanohttp

Re: XML::LibXML https
by KevinZwack (Chaplain) on Nov 30, 2013 at 22:10 UTC

    Here is another small example with LWP... You can easily add authentication or other features with it.

    #!/usr/bin/perl use warnings "all"; use strict; use LWP; use XML::LibXML; my $ua = LWP::UserAgent->new(); my $response = $ua->get('http://www.yourWebsite.com'); my $tree = XML::LibXML->load_xml(string => $response->content, recover +=>2); print $tree->toString();
Re: XML::LibXML https
by sundialsvc4 (Abbot) on Dec 02, 2013 at 04:30 UTC

    As far as I am aware, the two are really not related at all.   HTTP(S) is a communications protocol, definitively handled by packages such as LWP, which is capable of handling any sort of content.   Meanwhile, XML is a data representation format which can be used in any context ... with stuff that is transmitted, and/or with stuff that is stored in disk files.   If your HTTP(S) message contains XML content, then you can use LWP to retrieve it, then LibXML to decode it.   First one, then the other.

Re: XML::LibXML https
by marcelr (Initiate) on Oct 02, 2014 at 10:00 UTC

    If you do not have LWP::Protocol::https, the useragent get will fail to retrieve the file over https.

    Another problem: if the file contains an import that refers to yet another https file, you could pass it as a string to libxml. That works. But if you would parse it with LibXSLT as a next step, libxslt will give you a error "failed to load external entity" on the import href.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1064995]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-12-21 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (105 votes), past polls