NOTE: You can skip the intro. Though it does tell you how i got to whe +re im at with this. BEGIN INTRO: ############################################## A funny thing happened at work. I was hired because of my perl, and after i arrived they decided to standarize on python. This was after i was tasked with writing a client for our QA department so that we could automate whitebox testing by by-passing the front end of our website. Needless to say i am now working at an all MS house and they think perl is for Linux/Unix only. i guess they never have heard of ActiveState. Well after spending a week learning python and writing a client that can deal with cookies and redirects, the con +versation went like this: Boss: How long until the backend client is done? me: i'm not sure. B: Why? m: Python has blocking sockets by default and their socket.setblocking +(0) function doesnt. B: doesnt what? m: function. B: Have you asked for help? m: im the only one here who knows python. B: Then why did we standardize on that? m: i wanted perl B: but your the only who knows perl. m: im also the only one who knows python. B: if you wrote the backend client in perl it would take to long m: No, it wouldnt the moduals are already written i just have to script them together. B: How long would that take? m: About a day. B: Howmuch longer in python? m: i dont know ... ive only been using python for about a week. B: just get it done. m: perl it is then. END INTRO######################################################### so the problem is HTTP::Cookies which ive never used before. i'm sure i have all the pieces here but NOT in the right order or something. They symptom is this: I can create the cookie jar but neither the $cjar->save() function se +ems to work nor the $cjar->extract_cookies($response) seems to work. It will create the cookie jar file, but NOT write anyting to it. Out of curiosity i drilled down into the header object just to see if +the cookies are there and like automagic they indeed were there. But accessing them.... im l +ost. So im posting a limited piece of code that gives me the problem that i +ve just described. #!/usr/bin/perl use URI; use LWP::UserAgent; use HTTP::Request; use HTTP::Headers; use HTTP::Response; use HTTP::Cookies; # Create a cookie jar. Hard coding the name of the file for now. #putting in a headers object incase we need it later on. $cookie_jar = HTTP::Cookies->new('cookies.txt'); my $hdrs = new HTTP::Headers(); # get a url object and a request object so we can go cruseing down the + web my $url = new URI::URL('http://foo.com'); my $req = new HTTP::Request(GET, $url, $hdrs); #make a useragent so we can spoof the server as to what client we actu +ally are #NOTE: this is importaint because the site i work at only supports IE my $ua = new LWP::UserAgent; $ua->agent('Mozilla/4.0 (Compatable; MSIE 5.01; Windows NT 5.0)'); # Send out the request my $responce = $ua -> request($req); #save our cookies for a rainy day in cookies.txt $cookie_jar->extract_cookies($responce); if($responce->is_success) { #make sure we saved the cookies $cookie_jar->save('cookies.txt'); print $responce->content; } else { print $responce->error_as_HTML; } Now, at this point i get a file 'cookies.txt' but no cookies. I know that the cookies are indeed being sent by telneting to port 80 and issueing a GET /default.asp HTTP\1.1\n\n and looking at the header and ive drilled down into the responce object and verified that + the cookies are indeed in there about 3 levels or so down in a hash of a h +ash of hashes (or is that son of a son of a son of a salor?) So i've verified the data is there. The documentation maintains that the both $cjar->extract_cookies($resp +) and $cjar->save([file]) BOTH save the cookies to the cookie jar. I've verified that i have write perms to the box im using. I've taken the script an installed it on a Linux 5.x box ran it and verified that indeed it still will create the file but not save the da +ta. What am i missing?
Russ
Brainbench 'Most Valuable Professional' for Perl
In reply to HTTP::Cookies what am i missing? (Moved from Q&A) by Russ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |