Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

LWP and HTTPS once again!

by Gangabass (Vicar)
on Apr 29, 2014 at 17:17 UTC ( #1084362=perlquestion: print w/replies, xml ) Need Help??

Gangabass has asked for the wisdom of the Perl Monks concerning the following question:

The code below gives me an error:

Error GETing Can't connect to
use WWW::Mechanize; use CACertOrg::CA; my $mech = WWW::Mechanize->new(); $mech->agent_alias("Windows IE 6"); $mech->ssl_opts( SSL_version => 'SSLv23:TLSv1_2' ); #$mech->ssl_opts( verify_hostname => 1 ); #$mech->ssl_opts( SSL_ca_file => $Bin . "/curl-ca-bundle.crt" ); $mech->get(" +ew/index#ios/all/month/all");
But simple cURL request works:
C:\Users\roman>curl -v +pp-ios#/overview/index#ios/all /month/all * Hostname was NOT found in DNS cache * Trying * Connected to ( port 443 (#0) * successfully set certificate verify locations: * CAfile: C:\Program Files\cURL\bin\curl-ca-bundle.crt CApath: none * SSLv3, TLS handshake, Client hello (1): * SSLv3, TLS handshake, Server hello (2): * SSLv3, TLS handshake, CERT (11): * SSLv3, TLS handshake, Server finished (14): * SSLv3, TLS handshake, Client key exchange (16): * SSLv3, TLS change cipher, Client hello (1): * SSLv3, TLS handshake, Finished (20): * SSLv3, TLS change cipher, Client hello (1): * SSLv3, TLS handshake, Finished (20): * SSL connection using TLSv1.2 / AES128-SHA256 * Server certificate: * subject: OU=Domain Control Validated; * start date: 2013-08-05 10:29:01 GMT * expire date: 2015-08-05 10:29:01 GMT * subjectAltName: matched * issuer: C=US; ST=Arizona; L=Scottsdale;, Inc.; +OU= .com/repository; CN=Go Daddy Secure Certification Authority; serialNum +ber=07969287 * SSL certificate verify ok. > GET /home/revision-app-ios HTTP/1.1 > User-Agent: curl/7.36.0 > Host: > Accept: */* > < HTTP/1.1 302 Found < Cache-Control: private < Content-Type: text/html; charset=utf-8 < Location: /login?ReturnUrl=%2fhome%2frevision-app-ios * Server Microsoft-IIS/8.0 is not blacklisted < Server: Microsoft-IIS/8.0 < X-AspNetMvc-Version: 4.0 < X-AspNet-Version: 4.0.30319 < X-Powered-By: ASP.NET < Date: Tue, 29 Apr 2014 17:00:15 GMT < Content-Length: 160 < <html><head><title>Object moved</title></head><body> <h2>Object moved to <a href="/login?ReturnUrl=%2fhome%2frevision-app-i +os">here</a>.</h2> </body></html> * Connection #0 to host left intact

I think the problem is in IO::Socket::SSL SSL_version setting:

SSL_version Sets the version of the SSL protocol used to transmit data. 'SSLv23' auto-negotiates between SSLv2 and SSLv3, while 'SSLv2', 'SSLv3', 'TLSv1', 'TLSv1_1' or 'TLSv1_2' restrict the protocol to the specified version. All values are case-insensitive. Instead of 'TLSv1_1' and 'TLSv1_2' one can also use 'TLSv11' and 'TLSv12'. Support for 'TLSv1_1' and 'TLSv1_2' requires recent versions of Net::SSLeay and openssl. You can limit to set of supported protocols by adding !version separated by ':'. The default SSL_version is 'SSLv23:!SSLv2' which means, that SSLv2, SSLv3 and TLSv1 are supported for initial protocol handshakes, but SSLv2 will not be accepted, leaving only SSLv3 and TLSv1. You can also use !TLSv1_1 and !TLSv1_2 to disable TLS versions 1.1 and 1.2 while allowing TLS version 1.0. Setting the version instead to 'TLSv1' will probably break interaction with lots of clients which start with SSLv2 and then upgrade to TLSv1. On the other side some clients just close the connection when they receive a TLS version 1.1 request. In this case setting the version to 'SSLv23:!SSLv2:!TLSv1_1:!TLSv1_2' might help.
but I have tried different combination with no luck :-( Can you please help me to make a connection to such site or explain why my code is not working. Thanks. Roman

Replies are listed 'Best First'.
Re: LWP and HTTPS once again!
by rnewsham (Curate) on Apr 29, 2014 at 20:24 UTC

    Your code gives an "invalid SSL_version specified" error, I removed the SSL_version and it runs without error.

    I added a print to check the received page and everything looks right.

    Here is the modified code.

    use strict; use warnings; use WWW::Mechanize; use CACertOrg::CA; my $mech = WWW::Mechanize->new(); $mech->agent_alias("Windows IE 6"); $mech->get(" +ew/index#ios/all/month/all"); print $mech->content();

    This indicates that the problem is your system not the code, I hope that helps narrow it down.

Re: LWP and HTTPS once again!
by Gangabass (Vicar) on Apr 30, 2014 at 01:58 UTC
    Sorry it was broken Net::SSLeay install! After update (version 1.58) I have no more error:
    my $mech = WWW::Mechanize->new(); $mech->get($url);
Re: LWP and HTTPS once again!
by Anonymous Monk on Apr 29, 2014 at 23:43 UTC
    Ordinarily you should not need to specify the SSL version anyway. Browsers around the world do not.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1084362]
Approved by mr_mischief
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-01-26 16:44 GMT
Find Nodes?
    Voting Booth?