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 <tcha...@arx.gr> 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-unsubscr...@perl.apache.org
For additional commands, e-mail: asp-h...@perl.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscr...@perl.apache.org
For additional commands, e-mail: asp-h...@perl.apache.org