LWP-UserAgent-Request.pl - Login to facebook.com

This section provides a tutorial example on how to use LWP-UserAgent-Request.pl to login to facebook.com. The key part is to figure out the POST URI and data value names from HTML form source code.

Ready to try to login to facebook.com with LWP-UserAgent-Request.pl? Here is my test result:

herong> LWP-UserAgent-Request.pl GET http://www.facebook.com

GET http://www.facebook.com
User-Agent: Mozilla/5.0 (Windows NT 6.1)

HTTP/1.1 301 Moved Permanently
Location: https://www.facebook.com/
...

GET https://www.facebook.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1)

HTTP/1.1 200 OK
Set-Cookie: datr=PFQSUx4ndUAvvRdpNGJj_ANT; ...
...

herong> LWP-UserAgent-Request.pl
   POST https://www.facebook.com/login.php?login_attempt=1
   "email=your_email&pass=your_pass"

POST https://www.facebook.com/login.php?login_attempt=1
User-Agent: Mozilla/5.0 (Windows NT 6.1)
Content-Type: application/x-www-form-urlencoded
Cookie: datr=PFQSUx4ndUAvvRdpNGJj_ANT; ...
Cookie2: $Version="1"

email=your_email&pass=your_pass

HTTP/1.1 200 OK
...

<!DOCTYPE html>
<html lang="en" id="facebook" class="no_js">
...
</body></html>

The output confirms that the cookie management logic is working:

When I saved the last response into an HTML file and viewed it in a real browser, It showed the "The password you entered is incorrect. Please try again (make sure your caps lock is off)" message because entered a wrong password.

Now you can try to use LWP-UserAgent-Request.pl to play with your own Web applications. The key part of using LWP-UserAgent-Request.pl is that you have to figure out the POST URI and data value names from HTML form source code.

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Image and Picture Processing

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server

 CGI.pm Module for Building Web Pages

LWP::UserAgent and Web Site Testing

 What Is LWP::UserAgent?

 What Is HTTP::Response?

 What Is HTTP::Request?

 LWP-UserAgent-GET.pl - Sending a GET Request

 LWP-UserAgent-GET-Redirect.pl - Following HTTP Redirects

 http-equiv="Refresh" Meta Tag not Followed

 LWP-UserAgent-POST.pl - Posting Form Data

 post() Method not Following Redirect Location

 LWP-UserAgent-POST-Redirect.pl - Posting with Redirects

 What Is HTTP::Cookies?

 LWP-UserAgent-Request.pl - GET, POST and Cookies

LWP-UserAgent-Request.pl - Login to facebook.com

 HTTP::Cookies save() not Saving Temporary Cookies

 LWP-UserAgent-Request-Cookies.pl - Sending Request with Cookies

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS

 Archived Tutorials

 References

 Full Version in PDF/EPUB