Gossamer Forum
Home : General : Perl Programming :

Parallel User Agent with sessions?

Quote Reply
Parallel User Agent with sessions?
The Parallel User Agent package does not seem to support "Parallel Interactive Clients". In other words, I need each worker client to get a session cookie and use that cookie to make multiple requests and then logout at the end of its job.

Am I correct in assuming that Parallel User Agent only supports clients who are making one single request at a time? Can anyone suggest how they might handle this situation? I am trying to simulate the workflow of users in the system and create a load testing tool.

Last edited by:

mozkill: Apr 21, 2003, 4:22 PM
Quote Reply
Re: [mozkill] Parallel User Agent with sessions? In reply to
hi. your post got my attention because i have recently finished a project using LWP::UserAgent with session cookies.

in a course i am taking at college, our assignment was actually to make a malicious virus. i made a standalone win32 perl program that acts as a keylogger. it remains dormant until the user goes to paypal.com and logs in. my program uses OpenSSL, Crypt-SSLeay, and LWP::UserAgent in order to use the information obtained from the keylogging and actually logs into the paypal account. the session is maintained and the program obtains the account balance and then sends it to another paypal account.

well anyways, i'm sure you didn't need to know that. i just felt the need to elaborate on how i used the code i am giving you.

here is a small example on how you can go about what you want to do..

Code:
#!perl

use strict;
use HTTP::Request::Common qw!GET POST!;
use HTTP::Cookies ();
use LWP::UserAgent ();

my $ua = LWP::UserAgent->new;
my $cookie_jar = HTTP::Cookies->new (); # where all cookies are stored

$ua->cookie_jar ($cookie_jar);
$ua->agent ("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); # pretends to be IE6

# example using HTTP GET method
my $request = GET "http://www.yahoo.com/";
my $response = $ua->simple_request ($request);
$cookie_jar->extract_cookies ($response); # stores cookies (if any) into cookie jar.
my $content = $response->content; # yahoo's sourcecode

# example using HTTP POST method
$request = POST "http://mail.yahoo.com/", [
'username' => 'johnsmith',
'password' => 'abc123',
'submit' => 'Login'
];
$response = $ua->simple_request ($request);
$cookie_jar->extract_cookies ($response);
$content = $response->content;



$cookie_jar->clear (); # you should always get rid of the cookies.


that is just to serve as an example of how you would get session cookies. that mail.yahoo.com example doesn't actaully do anything. i was just trying to show you how you can submit login forms with the code. it is acutally possible to login to yahoo and download your mail through perl. it involves a lot of redirecting and a lot of parsing.

i suggest that you create a subroutine to get the content of the page and also automate the redirecting process. UserAgent has the $response->is_redirect boolean and the URL stored in $response->header ('Location'). in my program, i made a routine with a loop that automatically redirects (by retrieving the redirect page) until it gets to a page with content. it gets highly complicated with the login processes of sites like hotmail or paypal. there are numerous redirects and each one requires you to extract cookies from the headers. also, sometimes they redirect using the meta tag rather than with a Location header. this is why making a routine with a loop can be essential to your program.

in order to get an HTTPS connection, you need to have the protocol installed.

Last edited by:

uclajsn: Apr 26, 2003, 8:50 AM
Quote Reply
Re: [uclajsn] Parallel User Agent with sessions? In reply to
How did you detect key strokes from your perl script?
Quote Reply
Re: [uclajsn] Parallel User Agent with sessions? In reply to
the user cookie part was easy for me. the problem was running my script in multiple threads in one JVM. i have since given up trying to do this because it seems ALL parallel perl libraries are written only for the unix platform and windows doesn't have anything useful. now im just using OpenSTA to do my load testing. i gave up on using Perl.