LWP::UserAgent Can't Post with TLS1.1

2019-04-30 01:45发布

问题:

Getting 500 handshaker error:443 over https. The host service I am sending XML to does not support TLS 1.2, they do support 1.0 and 1.1. Currently using LWP 6.03 on CentOS 6. Using the code below they claim I am still sending using TLS1.2

use LWP::UserAgent;
$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0,SSL_version => 'SSLv23:!TLSv12' });
$req = HTTP::Request->new(GET => 'https://secure-host-server');

$res = $ua->request($req);
if ($res->is_success) {
  print $res->content;
  } else {
  print "Error: " . $res->status_line . "\n";
  }

Is it possible to print the TLS version as it is sent to the host? Anything I can do to verify I am using TLS1.1?

回答1:

Setting SSL_version via LWP::UserAgent would not work. I tried countless methods to try to get my code to send XML via TLSv1 without luck, The following code did the trick.

use Net::SSLGlue::LWP; 
use IO::Socket::SSL;

my $context = new IO::Socket::SSL::SSL_Context(
  SSL_version => 'tlsv1',
  SSL_verify_mode => Net::SSLeay::VERIFY_NONE(),
  );
IO::Socket::SSL::set_default_context($context);

use LWP::UserAgent;
use HTTP::Request::Common;