M
Michael Capone
Hi folks,
I'm using perl (actually, mod_perl environment on RH 8.0) to connect
to an external SSL server. I feed it an XML request and get a
response back. The problem is, the server is flaky, and I'd like to
be able to timeout / break if I haven't gotten a response in X
seconds. (Note that the server may connect, but simply not send a
response, i.e., it's too busy.)
I don't really understand filehandles and setting timeouts in unix /
perl as much as I should. The code below was lifted from the
Net::SSLeay readme and worked, and I never questioned it further.
Could someone show me how to modify the code below to add my timeout?
Note that I'm also completely open to other methods of connecting to
an SSL server; the Net::SSLeay method seemed to be the quickest to
implement, and I have no idea if there's a better way out there.
Thanks!
Michael
#!/usr/local/bin/perl -w
use strict;
use Net::SSLeay::Handle qw/shutdown/;
my ($request, $response) ;
local *F;
my $FH = *F;
$request = <<ENDXML;
<?xml version="1.0"?>
<Request>
<UserId>user1</UserId>
<Password>pass1</Password>
</Request>
ENDXML
my ($host, $port) = ("www.some.server", 443);
tie(*SSL, "Net::SSLeay::Handle", $host, $port);
print SSL "POST /xmlapps/blah HTTP/1.0\n";
print SSL "Content-type: application/x-www-form-urlencoded\n";
print SSL "Content-length: " . length($request) . "\n\n";
print SSL $request;
shutdown(\*SSL, 1);
$response .= $_ while (<SSL>);
close SSL;
print $response;
I'm using perl (actually, mod_perl environment on RH 8.0) to connect
to an external SSL server. I feed it an XML request and get a
response back. The problem is, the server is flaky, and I'd like to
be able to timeout / break if I haven't gotten a response in X
seconds. (Note that the server may connect, but simply not send a
response, i.e., it's too busy.)
I don't really understand filehandles and setting timeouts in unix /
perl as much as I should. The code below was lifted from the
Net::SSLeay readme and worked, and I never questioned it further.
Could someone show me how to modify the code below to add my timeout?
Note that I'm also completely open to other methods of connecting to
an SSL server; the Net::SSLeay method seemed to be the quickest to
implement, and I have no idea if there's a better way out there.
Thanks!
Michael
#!/usr/local/bin/perl -w
use strict;
use Net::SSLeay::Handle qw/shutdown/;
my ($request, $response) ;
local *F;
my $FH = *F;
$request = <<ENDXML;
<?xml version="1.0"?>
<Request>
<UserId>user1</UserId>
<Password>pass1</Password>
</Request>
ENDXML
my ($host, $port) = ("www.some.server", 443);
tie(*SSL, "Net::SSLeay::Handle", $host, $port);
print SSL "POST /xmlapps/blah HTTP/1.0\n";
print SSL "Content-type: application/x-www-form-urlencoded\n";
print SSL "Content-length: " . length($request) . "\n\n";
print SSL $request;
shutdown(\*SSL, 1);
$response .= $_ while (<SSL>);
close SSL;
print $response;