Answer the question
In order to leave comments, you need to log in
perl: lwp and https
I'm trying to send a POST request to a server over https using LWP.
Here is the code:
Here is the result:
The certificate on the server is self-signed.
solution
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
does not fit.
You need to verify the certificate locally.
in the line
SSL_ca_file => '/home/newdeveloper/certs/ca-crt.pem',
I substituted the server certificate, then pem certificate file, nothing helps.
what is the problem? I've been fighting for a long time.
#!/usr/bin/perl
use LWP::UserAgent;
use LWP::Debug qw(+);
use IO::Socket::SSL qw(debug3);
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");
$ua->ssl_opts(
SSL_ca_file => '/home/newdeveloper/certs/ca-crt.pem',
);
my $req = HTTP::Request->new(POST => 'www.server/path');
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');
my $res = $ua->request($req);
print $res->headers_as_string;
# Check the outcome of the response
if ($res->is_success) {
print $res->content;
}
else {
print $res->status_line, "\nerror\n";
}
DEBUG: .../IO/Socket/SSL.pm:1482: new ctx 460343328
DEBUG: .../IO/Socket/SSL.pm:334: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:336: socket connected
DEBUG: .../IO/Socket/SSL.pm:349: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:1470: ok=0 cert=460964448
DEBUG: .../IO/Socket/SSL.pm:392: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:1213: SSL connect attempt failed with unknown errorerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
DEBUG: .../IO/Socket/SSL.pm:398: fatal SSL error: SSL connect attempt failed with unknown errorerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
DEBUG: .../IO/Socket/SSL.pm:1213: IO::Socket::INET configuration failederror:00000000:lib(0):func(0):reason(0)
DEBUG: .../IO/Socket/SSL.pm:1519: free ctx 460343328 open=460343328
DEBUG: .../IO/Socket/SSL.pm:1524: free ctx 460343328 callback
DEBUG: .../IO/Socket/SSL.pm:1527: OK free ctx 460343328
Content-Type: text/plain
Client-Date: Mon, 16 Jan 2012 15:53:41 GMT
Client-Warning: Internal response
500 Can't connect to server:443 (certificate verify failed)
error
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question