Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ASP

Capture sessionID in browser from perl script

 

 

ModPerl asp RSS feed   Index | Next | Previous | View Threaded


sudarshan12s at gmail

Apr 1, 2009, 2:24 AM

Post #1 of 10 (12309 views)
Permalink
Capture sessionID in browser from perl script

Hi All,
I have a requirement to test webserver using perl scripts. The
webserver creates a sessionId after successfull authentication. Hence
for futher requests to the webserver, i need to send the sessionId
which is set in the browser/client . Can anyone please let me know how
can i do this.

Myperl script is something like this:

$requestString = "http://x.y.x.w"
$request = HTTP::Request->new(GET => $requestString);
$request->authorization_basic($userid, $passwd);
$request->push_header(Cookie => "SESSIONID=?????; path=/;"); ------>
capture session id from browser



Best Regards,
Pavan

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


tchatzi at arx

Apr 1, 2009, 2:50 AM

Post #2 of 10 (12067 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

O/H Sudarshan Soma έγραψε:
> Hi All,
> I have a requirement to test webserver using perl scripts. The
> webserver creates a sessionId after successfull authentication. Hence
> for futher requests to the webserver, i need to send the sessionId
> which is set in the browser/client . Can anyone please let me know how
> can i do this.
>
> Myperl script is something like this:
>
> $requestString = "http://x.y.x.w"
> $request = HTTP::Request->new(GET => $requestString);
> $request->authorization_basic($userid, $passwd);
> $request->push_header(Cookie => "SESSIONID=?????; path=/;"); ------>
> capture session id from browser
>
rather:
---8<---
use HTTP::Cookies;
use HTTP::Request::Common;
use LWP::UserAgent;

$ua = LWP::UserAgent->new;
$requestString = "http://x.y.x.w";
$ua->cookie_jar(HTTP::Cookies->new);
$result = $ua->request(HTTP::Request::Common::GET $requestString));
$ua->cookie_jar->extract_cookies($res);
#session id is now in the cookie jar. ``perldoc HTTP::Cookies''
#to read it
$anotherURI = "http://x.y.x.w/whatever";
$requestObject = HTTP::Request::Common::GET $anotherURI;
#automatically add the cookies (including the session-id) to this request..
$ua->cookie_jar->add_cookie_header($requestObject);
$result = $ua->request($requestObject);

---8<---

>
>
> Best Regards,
> Pavan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: asp-unsubscribe [at] perl
> For additional commands, e-mail: asp-help [at] perl
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


sudarshan12s at gmail

Apr 3, 2009, 7:05 AM

Post #3 of 10 (12031 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

Thanks a lot . I have a followup query, can anyone please advice me:

My application (webser) will set up sessionId in the cookie and sets
redirect URL to main page(if login is successfull). In case of
browser, this works fine with redirect thread reaches server with the
sessionId set and request for main page.

Can anyone please let me know how, it can be made to work in perl with
redirect URLs.

I think this is a basic query , but my intial search didnt help me.
Please advice

Thanks and Best Regards,
Pavan

My code till now is:

$ua = new LWP::UserAgent;
if(! $ua) {
return 0;
}

$ua->cookie_jar(HTTP::Cookies->new);
$requestString = "http://x.y.z.w?Username=abc&Password=abc";
$requestObject = HTTP::Request::Common::GET $requestString;
$result = $ua->request($requestObject);
$resp = $result->content;
print "$resp";


On Wed, Apr 1, 2009 at 3:20 PM, Thanos Chatziathanassiou <tchatzi [at] arx> wrote:
> O/H Sudarshan Soma :
>>
>> Hi All,
>> I have a requirement to test webserver using perl scripts. The
>> webserver creates a sessionId after successfull authentication. Hence
>> for futher requests to the webserver, i need to send the sessionId
>> which is set in the browser/client . Can anyone please let me know how
>> can i do this.
>>
>> Myperl script is something like this:
>>
>> $requestString = "http://x.y.x.w"
>> $request = HTTP::Request->new(GET => $requestString);
>> $request->authorization_basic($userid, $passwd);
>> $request->push_header(Cookie => "SESSIONID=?????; path=/;"); ------>
>> capture session id from browser
>>
>
> rather:
> ---8<---
> use HTTP::Cookies;
> use HTTP::Request::Common;
> use LWP::UserAgent;
>
> $ua = LWP::UserAgent->new;
> $requestString = "http://x.y.x.w";
> $ua->cookie_jar(HTTP::Cookies->new);
> $result = $ua->request(HTTP::Request::Common::GET $requestString));
> $ua->cookie_jar->extract_cookies($res);
> #session id is now in the cookie jar. ``perldoc HTTP::Cookies''
> #to read it
> $anotherURI = "http://x.y.x.w/whatever";
> $requestObject = HTTP::Request::Common::GET $anotherURI;
> #automatically add the cookies (including the session-id) to this request..
> $ua->cookie_jar->add_cookie_header($requestObject);
> $result = $ua->request($requestObject);
>
> ---8<---
>
>>
>>
>> Best Regards,
>> Pavan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: asp-unsubscribe [at] perl
>> For additional commands, e-mail: asp-help [at] perl
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


tchatzi at arx

Apr 3, 2009, 7:25 AM

Post #4 of 10 (12050 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

O/H Sudarshan Soma :
> Thanks a lot . I have a followup query, can anyone please advice me:
>
> My application (webser) will set up sessionId in the cookie and sets
> redirect URL to main page(if login is successfull). In case of
> browser, this works fine with redirect thread reaches server with the
> sessionId set and request for main page.
>
> Can anyone please let me know how, it can be made to work in perl with
> redirect URLs.
>
> I think this is a basic query , but my intial search didnt help me.
> Please advice
>
You really need to familiarize yourself with perldoc (or google for that
matter ;)

To the matter at hand: redirects should work quite as expected. If they
do not, then they're probably not HTTP 3xx (see
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) and perhaps
you'll have to resort to some fancy regex (perldoc perlre) to go to the
correct URI.
For HTTP, see ``$ua->max_redirect'' and ``$ua->requests_redirectable''
in ``perldoc LWP::UserAgent''. Also take a look in the libwww-perl
cookbook ``perldoc lwpcook''.
Someone's bound to have already done what you need.
> Thanks and Best Regards,
> Pavan
>
> My code till now is:
>
> $ua = new LWP::UserAgent;
> if(! $ua) {
> return 0;
> }
>
> $ua->cookie_jar(HTTP::Cookies->new);
> $requestString = "http://x.y.z.w?Username=abc&Password=abc";
> $requestObject = HTTP::Request::Common::GET $requestString;
> $result = $ua->request($requestObject);
> $resp = $result->content;
> print "$resp";
>
>
> On Wed, Apr 1, 2009 at 3:20 PM, Thanos Chatziathanassiou <tchatzi [at] arx> wrote:
>
>> O/H Sudarshan Soma :
>>
>>> Hi All,
>>> I have a requirement to test webserver using perl scripts. The
>>> webserver creates a sessionId after successfull authentication. Hence
>>> for futher requests to the webserver, i need to send the sessionId
>>> which is set in the browser/client . Can anyone please let me know how
>>> can i do this.
>>>
>>> Myperl script is something like this:
>>>
>>> $requestString = "http://x.y.x.w"
>>> $request = HTTP::Request->new(GET => $requestString);
>>> $request->authorization_basic($userid, $passwd);
>>> $request->push_header(Cookie => "SESSIONID=?????; path=/;"); ------>
>>> capture session id from browser
>>>
>>>
>> rather:
>> ---8<---
>> use HTTP::Cookies;
>> use HTTP::Request::Common;
>> use LWP::UserAgent;
>>
>> $ua = LWP::UserAgent->new;
>> $requestString = "http://x.y.x.w";
>> $ua->cookie_jar(HTTP::Cookies->new);
>> $result = $ua->request(HTTP::Request::Common::GET $requestString));
>> $ua->cookie_jar->extract_cookies($res);
>> #session id is now in the cookie jar. ``perldoc HTTP::Cookies''
>> #to read it
>> $anotherURI = "http://x.y.x.w/whatever";
>> $requestObject = HTTP::Request::Common::GET $anotherURI;
>> #automatically add the cookies (including the session-id) to this request..
>> $ua->cookie_jar->add_cookie_header($requestObject);
>> $result = $ua->request($requestObject);
>>
>> ---8<---
>>
>>
>>> Best Regards,
>>> Pavan
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: asp-unsubscribe [at] perl
>>> For additional commands, e-mail: asp-help [at] perl
>>>
>>>
>>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


sudarshan12s at gmail

Apr 8, 2009, 10:23 PM

Post #5 of 10 (11987 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

2009/4/3 Thanos Chatziathanassiou <tchatzi [at] arx>:
> O/H Sudarshan Soma :
>>
>> Thanks a lot . I have a followup query, can anyone please advice me:
>>
>> My application (webser) will set up sessionId in the cookie and sets
>> redirect URL to main page(if login is successfull). In case of
>> browser, this works fine with redirect thread reaches server with the
>> sessionId set and request for main page.
>>
>> Can anyone please let me know how, it can be made to work in perl with
>> redirect URLs.
>>
>> I think this is a basic query , but my intial search didnt help me.
>> Please advice
>>
>
> You really need to familiarize yourself with perldoc (or google for that
> matter ;)
>
> To the matter at hand: redirects should work quite as expected. If they do
> not, then they're probably not HTTP 3xx (see
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) and perhaps you'll
> have to resort to some fancy regex (perldoc perlre) to go to the correct
> URI.
> For HTTP, see ``$ua->max_redirect'' and ``$ua->requests_redirectable'' in
> ``perldoc LWP::UserAgent''. Also take a look in the libwww-perl cookbook
> ``perldoc lwpcook''.
> Someone's bound to have already done what you need.
>>
>> Thanks and Best Regards,
>> Pavan
>>
>> My code till now is:
>>
>> $ua = new LWP::UserAgent;
>> if(! $ua) {
>> return 0;
>> }
>>
>> $ua->cookie_jar(HTTP::Cookies->new);
>> $requestString = "http://x.y.z.w?Username=abc&Password=abc";
>> $requestObject = HTTP::Request::Common::GET $requestString;
>> $result = $ua->request($requestObject);
>> $resp = $result->content;
>> print "$resp";
>>
>>
>> On Wed, Apr 1, 2009 at 3:20 PM, Thanos Chatziathanassiou <tchatzi [at] arx>
>> wrote:
>>
>>>
>>> O/H Sudarshan Soma :
>>>
>>>>
>>>> Hi All,
>>>> I have a requirement to test webserver using perl scripts. The
>>>> webserver creates a sessionId after successfull authentication. Hence
>>>> for futher requests to the webserver, i need to send the sessionId
>>>> which is set in the browser/client . Can anyone please let me know how
>>>> can i do this.
>>>>
>>>> Myperl script is something like this:
>>>>
>>>> $requestString = "http://x.y.x.w"
>>>> $request = HTTP::Request->new(GET => $requestString);
>>>> $request->authorization_basic($userid, $passwd);
>>>> $request->push_header(Cookie => "SESSIONID=?????; path=/;"); ------>
>>>> capture session id from browser
>>>>
>>>>
>>>
>>> rather:
>>> ---8<---
>>> use HTTP::Cookies;
>>> use HTTP::Request::Common;
>>> use LWP::UserAgent;
>>>
>>> $ua = LWP::UserAgent->new;
>>> $requestString = "http://x.y.x.w";
>>> $ua->cookie_jar(HTTP::Cookies->new);
>>> $result = $ua->request(HTTP::Request::Common::GET $requestString));
>>> $ua->cookie_jar->extract_cookies($res);
>>> #session id is now in the cookie jar. ``perldoc HTTP::Cookies''
>>> #to read it
>>> $anotherURI = "http://x.y.x.w/whatever";
>>> $requestObject = HTTP::Request::Common::GET $anotherURI;
>>> #automatically add the cookies (including the session-id) to this
>>> request..
>>> $ua->cookie_jar->add_cookie_header($requestObject);
>>> $result = $ua->request($requestObject);
>>>
>>> ---8<---
>>>
>>>
>>>>
>>>> Best Regards,
>>>> Pavan
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: asp-unsubscribe [at] perl
>>>> For additional commands, e-mail: asp-help [at] perl
>>>>
>>>>
>>>>
>>>
>>>
>
>


Thanks a lot. I got the final code now

use warnings;

use HTTP::Cookies;
use HTTP::Request::Common;
use LWP::UserAgent;

{
$ua = new LWP::UserAgent;
if(! $ua) {
print "Can not get the page :UserAgent fialed \n";
return 0;
}

my $cookies=new HTTP::Cookies(file=>'./cookies.dat',autosave=>1);
$ua->cookie_jar($cookies);
# push does all magic to exrtact cookies and add to header for further
reqs. useragent should be newer
push @{ $ua->requests_redirectable }, 'POST';
$result = $ua->request(POST "http://x.y.z.p",
{
Username =>'xxx',
Password =>'xxx',
Submit =>'Submit'
});
$resp = $result->content;

$anotherURI = "http://x.y.z.p/gd";
$requestObject = HTTP::Request::Common::GET $anotherURI;
$result = $ua->request($requestObject);
$resp = $result->content;

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


tchatzi at arx

Apr 9, 2009, 2:36 AM

Post #6 of 10 (11955 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

O/H Sudarshan Soma :
> Thanks a lot. I got the final code now
>
> use warnings;
>
Since this is a mod_perl list, you might want to consider ``use
strict;'' as well (actually you might consider using strict anyhow)
> use HTTP::Cookies;
> use HTTP::Request::Common;
> use LWP::UserAgent;
>
> {
> $ua = new LWP::UserAgent;
> if(! $ua) {
> print "Can not get the page :UserAgent fialed \n";
> return 0;
> }
>
I've never had an LWP::UserAgent fail on me at this step, however...
> my $cookies=new HTTP::Cookies(file=>'./cookies.dat',autosave=>1);
> $ua->cookie_jar($cookies);
> # push does all magic to exrtact cookies and add to header for further
> reqs. useragent should be newer
> push @{ $ua->requests_redirectable }, 'POST';
> $result = $ua->request(POST "http://x.y.z.p",
> {
> Username =>'xxx',
> Password =>'xxx',
> Submit =>'Submit'
> });
>
..if really want to check for failures, maybe fold all the rest in an
``if ($result->is_success)'' block.
> $resp = $result->content;
>
> $anotherURI = "http://x.y.z.p/gd";
> $requestObject = HTTP::Request::Common::GET $anotherURI;
> $result = $ua->request($requestObject);
>
same here
> $resp = $result->content;
>
in all, there are numerous things that might go wrong through the
process (e.g. perhaps you didn't really log in successfully), but maybe
this is a throw-away run once script, so if it works for you...


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


laki.sreekanth at gmail

Jun 18, 2009, 11:34 PM

Post #7 of 10 (11313 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

http://www.nabble.com/file/p24106268/final.pl final.pl
Here i am not getting the Session-id / cookie-value from the browser, just i
am getting the below output:
Output: HTTP::Response=HASH(0xacc640)

Please suggest me how to capture the session-id from the opened site(in the
script)

Thanks,
Lakshmi Sreekanth
--
View this message in context: http://www.nabble.com/Capture-sessionID-in-browser-from-perl-script-tp22822820p24106268.html
Sent from the Apache - Asp mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


laki.sreekanth at gmail

Jun 18, 2009, 11:40 PM

Post #8 of 10 (11301 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

My Perl code:

#!/usr/bin/perl -w

use HTTP::Cookies;
use HTTP::Request::Common;
use LWP::UserAgent;

$ua = new LWP::UserAgent;
if(! $ua)
{
print "Can not get the page :UserAgent fialed \n";
return 0;
}

my $cookies=new HTTP::Cookies(file=>'./cookies.dat',autosave=>1);
$ua->cookie_jar($cookies);
# push does all magic to exrtact cookies and add to header for further reqs.
useragent should be newer
push @{ $ua->requests_redirectable }, 'POST';
$result = $ua->request(POST " http://erail.in http://erail.in ");
print $result;
______________
Through this program i am not able to capture the Session id/cookie value
from the opened site(in the script)
I am getting this output: HTTP::Response=HASH(0xacc640)

Please suggest me how to capture the session-id....

Thanks,
Lakshmi Sreekanth
--
View this message in context: http://www.nabble.com/Capture-sessionID-in-browser-from-perl-script-tp22822820p24106307.html
Sent from the Apache - Asp mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


sudarshan12s at gmail

Jun 18, 2009, 11:54 PM

Post #9 of 10 (11317 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

Hi,
The cookies would be stored in the cookie store mentioned, cookies.dat.
You can aswell check errors for every call. In mycase if need not
check the sessionid, but just pass the obtained sessionid embedded in
the further web requests

let me know what u find

thanks
pavan

On Fri, Jun 19, 2009 at 12:10 PM, aura networks<laki.sreekanth [at] gmail> wrote:
>
> My Perl code:
>
> #!/usr/bin/perl -w
>
> use HTTP::Cookies;
> use HTTP::Request::Common;
> use LWP::UserAgent;
>
> $ua = new LWP::UserAgent;
> if(! $ua)
> {
> print "Can not get the page :UserAgent fialed \n";
> return 0;
> }
>
> my $cookies=new HTTP::Cookies(file=>'./cookies.dat',autosave=>1);
> $ua->cookie_jar($cookies);
> # push does all magic to exrtact cookies and add to header for further reqs.
> useragent should be newer
> push @{ $ua->requests_redirectable }, 'POST';
> $result = $ua->request(POST " http://erail.in http://erail.in ");
> print $result;
> ______________
> Through this program i am not able to capture the Session id/cookie value
> from the opened site(in the script)
> I am getting this output: HTTP::Response=HASH(0xacc640)
>
> Please suggest me how to capture the session-id....
>
> Thanks,
> Lakshmi Sreekanth
> --
> View this message in context: http://www.nabble.com/Capture-sessionID-in-browser-from-perl-script-tp22822820p24106307.html
> Sent from the Apache - Asp mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: asp-unsubscribe [at] perl
> For additional commands, e-mail: asp-help [at] perl
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


laki.sreekanth at gmail

Jun 19, 2009, 4:33 AM

Post #10 of 10 (11309 views)
Permalink
Re: Capture sessionID in browser from perl script [In reply to]

Contents in cookies.dat file: #LWP-Cookies-1.0
Output: HTTP::Response=HASH(0xafebd0)

Tell me the way to get session-id pls pls...



--
View this message in context: http://www.nabble.com/Capture-sessionID-in-browser-from-perl-script-tp22822820p24109775.html
Sent from the Apache - Asp mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl

ModPerl asp RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.