http://www.perlmonks.org?node_id=1018288

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

I am new to perl, below is the code that I have compiled and run to connect using a proxy to get response from the server which requires a client certificate. I am trying to figure out if issue is with my script or on the other end at the host site. Can someone please look at it and give me some directions how i can debug and see the problem. I get error 500 connection timeout when I run this script. Thanks

500 Connect failed: connect: Connection timed out; Connection timed ou +t header ----Content-Type: text/plain Client-Date: Client-Warning: Internal response response --- Connect failed: connect: Connection timed out; Connection timed out at + /usr/lib/perl5/site_perl/5.8.8/LWP/Protocol/http.pm line 31 $
#!/usr/bin/perl use LWP::UserAgent; use LWP::Simple; use HTTP::Request; use HTTP::Response; use strict; $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS}="Net::SSL"; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $ua = new LWP::UserAgent; $ua->timeout(30); $ua->agent(""); $ua->proxy('http', 'http://someproxy.com:80/'); my $h = HTTP::Headers->new(); $h->proxy_authorization_basic('userid','passwordforproxyserver'); #actual server trying to connect to #passing a certificate $ua->ssl_opts( # SSL_ca_file => 'caCertificate.pem', verfiy_hostname => 1, SSL_cert_file => '/home/cert/client_cert.crt', ); # make a https request my $req = HTTP::Request->new('GET', 'https://server.com:443', $h); my $res = $ua->request($req); if ($res->is_success){ print " testing \n " . $res->content; } print "header ----" . $res->headers_as_string; print "response ---" . $res->as_string;

Replies are listed 'Best First'.
Re: Using LWP Proxy and Client Certificate Connection timeout
by kcott (Archbishop) on Feb 12, 2013 at 07:46 UTC

    G'day kabachaa,

    Welcome to the monastery.

    I note you've set your timeout to 30 ($ua->timeout(30);). The LWP::UserAgent documentation gives the default as 180. Perhaps setting a longer timeout might help given the phrase Connection timed out appears several times in your output.

    Adding use warnings; (after use strict;) might provide some additional feedback.

    -- Ken

Re: Using LWP Proxy and Client Certificate Connection timeout
by Anonymous Monk on Feb 12, 2013 at 09:20 UTC
Re: Using LWP Proxy and Client Certificate Connection timeout
by Khen1950fx (Canon) on Feb 12, 2013 at 11:52 UTC
    Try it like this:
    #!/usr/bin/perl -l use strict; use warnings; use HTTP::Headers; use HTTP::Request; use LWP::UserAgent; my $https_proxy; my $url = 'https://someproxy.com:80'; my $ua = LWP::UserAgent->new( verify_hostname => 0, SSL_ca_file => 'cert.dat', ); $ua->timeout(10); $ua->agent(""); $ua->proxy( 'https', $https_proxy ); my $h = HTTP::Headers->new(); $h->proxy_authorization_basic( 'user', 'password' ); my $req = HTTP::Request->new( GET => $url ); my $res = $ua->request($req); print "header ----" . $res->headers_as_string; print "response ---" . $res->as_string;