HTTP Communication Level Debugging

This section provides a tutorial example on how to use Perl LWP package to simulate a Web browser and debug ASP pages at the HTTP communication level.

If you have a problem with your ASP application at the HTTP communication level, one good debugging tool is the Perl LWP package. It can be used as a Web browser to talk to your ASP application, and to log everything at the HTTP communication level.

Here is my sample Perl program, reg_client.pl, designed to work with my previous ASP registration application:

#- reg_client.pl
#- Copyright (c) 2002 by Dr. Herong Yang
  use LWP::Debug qw(+);
  use LWP::UserAgent;
  use HTTP::Cookies;
  ($url) = @ARGV;
  $url =  'http://localhost' unless $url;
  $ua = new LWP::UserAgent;
  $cookie_jar = HTTP::Cookies->new;
  &getForm();
  &submitForm();
  exit;
sub getForm {
  $u =  $url.'/reg_form.asp';
  my $req = new HTTP::Request GET => $u;
  my $res = $ua->request($req);
  $req = $res->request();
  $cookie_jar->extract_cookies($res);
  &dump($req,$res);
}
sub submitForm {
  $u =  $url.'/reg_form.asp?first_name=Herong&submit=Submit';
  my $req = new HTTP::Request GET => $u;
  $cookie_jar->add_cookie_header($req);
  my $res = $ua->request($req);
  $req = $res->request();
  $cookie_jar->extract_cookies($res);
  &dump($req,$res);
}
sub dump {
   local ($req,$res) = @_;
   print "\nREQUEST-HEADERS\n";
   print $req->headers_as_string();
   print "\nREQUEST-CONTENT\n";
   print $req->content;
   if ($res->is_success) {
      print "\nRESPONSE-HEADERS\n";
      print $res->headers_as_string();
      print "\nRESPONSE-CONTENT\n";
      print $res->content;
   } else {
      print "\nRESPONSE-ERROR\n";
      print $res->error_as_HTML();
   }
}

A couple of notes to help you to understand this program:

Table of Contents

 About This Book

 ASP (Active Server Pages) Introduction

 IIS (Internet Information Services) 5.0

 MS Script Debugger

 VBScript Language

 ASP Built-in Run-time Objects

ASP Session

 What Is Session?

 Properties and Methods of the "session" Object

 Passing Values between Pages

HTTP Communication Level Debugging

 HTTP Communication Log Example

 Creating and Managing Cookies

 Managing Sessions with and without Cookies

 scrrun.dll - Scripting Runtime DLL

 Managing Response Header Lines

 Calculation Speed and Response Time

 ADO (ActiveX Data Object) DLL

 Working with MS Access Database

 Guest Book Application Example

 References

 Full Version in PDF/EPUB