Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Using LWP Proxy and Client Certificate Connection timeout

by kabachaa (Novice)
on Feb 12, 2013 at 04:13 UTC ( #1018288=perlquestion: print w/replies, xml ) Need Help??
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 (Canon) 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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018288]
Approved by vinoth.ree
help
Chatterbox?
[Corion]: 1nickt: That one sounds sensible as it will tell you when it found an error
[1nickt]: Throws on error, I believe
[1nickt]: But should handle month as number or word
[TCLion]: I am breaking down the line and putting the date in the correct order during output
[TCLion]: at least that's the plan
[1nickt]: Corion this looks good, from the pod: "there are 9000+ variations that are detected correctly in the test files (see t/data/* for most of them). If you can think of any that I do not cover, please let me know."
[TCLion]: some moron put the date like this : Mon Feb 20 09:31:30 2017
[Corion]: 1nickt: Yes, the module sounds promising indeed
[1nickt]: "putting the date in correct order" how?
[Corion]: TCLion: Whee ;)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (17)
As of 2017-03-23 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (288 votes). Check out past polls.