Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Test Availability of HTTPS Web Application?

by Beau Landeaux (Novice)
on May 28, 2002 at 21:22 UTC ( #169914=perlquestion: print w/replies, xml ) Need Help??

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

My apologies if this question reeks of ignorance (I have intermediate Perl experience, zero web-application experience, but a great deal of experience with ignorance), but here is my task: from server-A, test the availability of a given web application on server-B. The URL that would be entered by the browser is as follows: "https://bogus.domain.com/rwi.do". All I need do at this point is ensure we receive a 200 status. We have some completely undocumented legacy Perl code that performs a login- or lookup-test via, LWP::UserAgent, HTTP::Status, HTTP::Request, and HTTP::Response, however, reverse engineering this has not been easy and my thought is, there's got'a be a better way. Any help is greatly appreciated. Beau
  • Comment on Test Availability of HTTPS Web Application?

Replies are listed 'Best First'.
Re: Test Availability of HTTPS Web Application?
by Kanji (Parson) on May 28, 2002 at 23:57 UTC

    I'm not sure why you need to 'reverse engineer' legacy Perl code (decipher, maybe ;^), but your right in thinking there's a better way ... well, simpler anyway.

    #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request::Common qw/ GET /; my $url = shift; my $browser = LWP::UserAgent->new; my $response = $browser->request( GET $url ); print $response->code;

    Personally, I think $response->is_success would be more beneficial as 200 isn't the only response indicating success, but that's your call...

    One caveat, tho:- test against a known good site before anything else ... LWP::UserAgent returns a 500 error instead of undef if you don't have have the modules necessary to talk to SSL (aka https) servers.

        --k.


      You're correct, "is_success" is MUCH better (I'm catchin' on.) Here's the rub: https, repeat 's'. Beau
        Go to the link mentioned as "required modules", i.e. Crypt::SSLeay: "OpenSSL glue that provides LWP https support"
Re: Test Availability of HTTPS Web Application?
by IlyaM (Parson) on May 29, 2002 at 10:39 UTC
    ++Kanji for LWP::UserAgent example. But Perl is TMTOWTDI. Here example which does similar thing via HTTP::WebTest.

    #!/usr/bin/perl -w use strict; use HTTP::WebTest; my $url = shift; my $wt = HTTP::WebTest->new; # runs test and generates test report $wt->run_tests([ { url => $url } ]);

    Note that you still have to install Crypt::SSL to get 'https' to work.

    --
    Ilya Martynov (http://martynov.org/)

      I installed prerequisites TermReadKey-2.20, File-Temp-0.12, and Time-HiRes-01.20, but make test fails at 50% (below). Any ideas? Thanks, Beau
      % perl Makefile.PL HTTP-WebTest requires installation of the http-webtest directory for running local file tests. If you don't use local file tests you can skip installation of this directory. Install http-webtest directory? (y/n): y Default directory to install the http-webtest directory in is /usr/l +ocal/etc, but you should probably use another location if MYSQL is installed. Install http-webtest directory in /usr/local/etc? (y/n): y WARNING: If your system does not have an HTTP connection to the Inte +rnet or your system requires a proxy HTTP server, the "make test" tests will + fail. Writing Makefile for HTTP::WebTest % make mkdir blib mkdir blib/lib mkdir blib/lib/HTTP mkdir blib/arch mkdir blib/arch/auto mkdir blib/arch/auto/HTTP mkdir blib/arch/auto/HTTP/WebTest mkdir blib/lib/auto mkdir blib/lib/auto/HTTP mkdir blib/lib/auto/HTTP/WebTest mkdir blib/man1 mkdir blib/man3 cp WebTest.pm blib/lib/HTTP/WebTest.pm mkdir blib/script cp wt blib/script/wt /usr/bin/perl -I/usr/local/lib/perl5/5.6.0/sun4-solaris -I/usr/local +/lib/perl5/5.6.0 -MExtUtils::MakeMaker -e "MY->fixin(shift)" blib/sc +ript/wt Manifying blib/man3/HTTP::WebTest.3 Manifying blib/man1/wt.1 % make test PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/usr/local/ +lib/perl5/5.6.0/sun4-solaris -I/usr/local/lib/perl5/5.6.0 -e 'use Tes +t::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t t/404...............ok t/cookie............NOK 1FAILED test 1 Failed 1/1 tests, 0.00% okay t/form..............NOK 1FAILED test 1 Failed 1/1 tests, 0.00% okay t/yahoo.............ok Failed Test Status Wstat Total Fail Failed List of failed -------------------------------------------------------------------- +----------- t/cookie.t 1 1 100.00% 1 t/form.t 1 1 100.00% 1 Failed 2/4 test scripts, 50.00% okay. 2/4 subtests failed, 50.00% ok +ay. *** Error code 29 make: Fatal error: Command failed for target `test_dynamic'
        As I understand you are trying last "stable" release of HTTP::WebTest. It's tests rely on avilability of external web sites so they can fail if there any networking problem. Probably there is no actually any problems. Anyway you may try latest "development" version (avialable from http://www.cpan.org/authors/id/I/IL/ILYAM/HTTP-WebTest-1.99_06.tar.gz) . It is going to become new "official stable" release very soon so don't be scared trying "beta".

        Moreover my example will work only with latest "development" version becauses it uses new API.

        --
        Ilya Martynov (http://martynov.org/)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://169914]
Approved by Zaxo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2022-06-30 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (97 votes). Check out past polls.

    Notices?