in reply to Cookie problems:

Unfortunately, your code looks okay... I would check to make sure you're sending the correct request to the server. I would also check out the LiveHTTPHeaders plugin for Firefox/Mozilla to verify that the server is responding to your particular request with a Set-Cookie header.

I'm including also some code that I just threw together (based on stuff at LWP) to test this, which definately works - it would log you in to PerlMonks and maintain the cookies in that cookie_jar file - which reminds me, when playing with these automated web-browsing scripts, its sometimes wiser to include a user-agent that looks like a regular ol' browser, in case the server gets confused.
use HTTP::Cookies; use LWP; $cookie_jar = HTTP::Cookies->new ( file => "cookie_jar.lwp", autosave => 1, ); $ua= LWP::UserAgent->new; $ua->cookie_jar( $cookie_jar ); $ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) +Gecko/20050317 Firefox/1.0.2"); my $req = HTTP::Request->new(POST => 'http://www.perlmonks.com/'); $req->content_type('application/x-www-form-urlencoded'); $req->content('node_id=131&op=login&user=Adrade&passwd=pass-goes-here& +expires=%2B10y&login=Login'); my $res = $ua->request($req); print $cookie_jar->as_string;


Best of luck,
  -Adam

--
By a scallop's forelocks!

Replies are listed 'Best First'.
Re^2: Cookie problems:
by Blue_eyed_son (Sexton) on Jul 14, 2005 at 16:26 UTC
    Hi Adam--Thank you for taking the time to write. I am using a browser-mimmicking user-agent with LWP with the search that is giving me cookie problems.
    So, I ran the script that you posted, and the cookie looked good. Yet still no dice on my original search.
    Could you tell me how the $req->content and $req->content_type commands work?
    I ran Firefox's live Headers when I originally put the post together, and here is what it looks like:
    Here is the original post:
    http://nl.newsbank.com/nl-search/we/Archives POST http://nl.newsbank.com/nl-search/we/Archives HTTP/1.1 Host: nl.newsbank.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) +Gecko/20050511 Firefox/1.0.4 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Referer: http://nl.newsbank.com/nl-search/we/Archives/?p_action=custom +ized&s_search_type=customized&p_product=NewsLibrary&p_theme=newslibra +ry2&d_sources=location&d_place=United%20States&p_nbid=& Cookie: JServSessionIdnewslib=lgfbb4ahn1.JS36b Proxy-Authorization: Basic c2NpY2FsYTphZWRmamtvOw== Content-Type: application/x-www-form-urlencoded Content-Length: 4721 s_siteloc=NL2&p_queryname=4000&p_action=search&p_product=NewsLibrary&p +_theme=newslibrary2&s_search_type=customized&d_sources=location&d_pla +ce=United+States&p_nbid=&p_field_psudo-sort-0=psudo-sort&f_multi=&p_m +ulti=PFNB%7CBEHB%7CCWCB%7CVC%7CKCJB%7CTNTB%7COLPB%7CIG%7CSE%7CSR%7CVB +JB%7CYHRB%7CPJCB%7COR%7CERGB%7CSSJB%7CCBWB%7CATSB%7CCFAB%7CACPB%7CBCA +B%7CCLFB%7CCERB%7CCLKB%7CCC%7CWDDB%7CLA%7CHDRB%7CDVTB%7CDVEB%7CDSSB%7 +CFBAB%7CFB%7CGZ%7CHNSB%7CVDBB%7CLOPC%7CRCPB%7CLCRB%7CLODB%7CLB%7CLBEB +%7CMIJB%7CMBNB%7CMSSB%7CMPPB%7CMS%7CMC%7CPCMB%7COKTB%7COC%7COMRB%7CPF +TB%7CPPOB%7CPNTB%7CSA%7CRS%7CRBDB%7CRDFB%7CRWTB%7CCVRB%7CSB%7CSDUN%7C +SFCB%7CSGVB%7CSJ%7CSMCB%7CSMTB%7CYCSB%7CPSWB%7CSBCB%7CTPRB%7CVTHB%7CE +TSB%7CTVHB%7CSO%7CTARB%7CUDJB%7CVCSB%7CVTDB%7CWDNB%7CWNCB%7CAS%7CFDNB +%7CJUEB%7CKTVB%7CHNAB%7CCDMB%7CCIZB%7CHHDB%7CDNLB%7CVNRB%7CVBOB%7CFFS +B%7CRTDB%7CRO%7CNK%7CACTB%7CCO%7CECDB%7CGVRB%7CFV%7CGB%7CDHSB%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B%7CCUJB%7CRDMB%7CEBAB%7CEBNB%7CEBCB%7 +CEQUB%7CFPGB%7CHDAB%7CHYRB%7CINWB%7CIBDB%7CIDGB%7CIMWB%7CMARB%7CDMJB% +7CMMEB%7CMVNB%7CTMTB%7CNMNB%7CNBRB%7CTMWB%7COTNB%7CTPAB%7CPPLB%7CRGRB +%7CSDNB%7CTMZB%7CTMBB%7CAPAB%7CBBAB%7CKR%7CSN%7CTNSB%7CWSOB%7CCNEB%7C +USLB%7CCBSB%7CCRSB%7CCNBB%7CCNNB%7CCNIB%7CCNFB%7CFDCB%7CFOXB%7CSNBB%7 +CNR%7CNBCB%7CCSMB%7CNWEC%7CUW&p_widesearch=smart&p_sort=YMD_date%3AD& +p_maxdocs=200&p_perpage=10&p_text_base-0=please+work&p_field_base-0=& +p_bool_base-1=AND&p_text_base-1=&p_field_base-1=&p_bool_base-2=AND&p_ +text_base-2=&p_field_base-2=&p_text_YMD_date-0=1%2F1%2F2000+to+6%2F1% +2F2000&p_field_YMD_date-0=YMD_date&p_params_YMD_date-0=date%3AB%2CE&p +_field_YMD_date-3=YMD_date&p_params_YMD_date-3=date%3AB%2CE&Search.x= +37&Search.y=21&Search=Search HTTP/1.x 200 OK Date: Thu, 14 Jul 2005 16:12:34 GMT Server: Apache/1.3.26 (Unix) ApacheJServ/1.1.2 Expires: Thu, 01 Jan 1970 00:00:00 GMT Pragma: no-cache Content-Type: text/html X-Cache: MISS from shade.uchicago.edu Proxy-Connection: close ---------------------------------------------------------- http://nl.newsbank.com/nl-search/we/Archives GET http://nl.newsbank.com/nl-search/we/Archives HTTP/1.1 Host: nl.newsbank.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) +Gecko/20050511 Firefox/1.0.4 Accept: */* Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Referer: http://nl.newsbank.com/nl-search/we/Archives Cookie: JServSessionIdnewslib=lgfbb4ahn1.JS36b Proxy-Authorization: Basic c2NpY2FsYTphZWRmamtvOw== HTTP/1.x 200 OK Date: Thu, 14 Jul 2005 16:12:55 GMT Server: Apache/1.3.26 (Unix) ApacheJServ/1.1.2 Cache-Control: no-store, no-cache, must-revalidate Expires: Thu, 01 Jan 1970 00:00:00 GMT Pragma: no-cache Content-Type: text/html X-Pad: avoid browser bug X-Cache: MISS from shade.uchicago.edu Proxy-Connection: close ---------------------------------------------------------- http://nl.newsbank.com/favicon.ico GET http://nl.newsbank.com/favicon.ico HTTP/1.1 Host: nl.newsbank.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) +Gecko/20050511 Firefox/1.0.4 Accept: image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Cookie: JServSessionIdnewslib=lgfbb4ahn1.JS36b Proxy-Authorization: Basic c2NpY2FsYTphZWRmamtvOw== HTTP/1.x 404 Not Found Date: Thu, 14 Jul 2005 16:12:58 GMT Server: Apache/1.3.26 (Unix) ApacheJServ/1.1.2 WWW-Authenticate: Basic realm="NewsLibrary" Last-Modified: Mon, 03 Nov 2003 15:41:26 GMT Etag: "1d3882-1491-3fa67726" Accept-Ranges: bytes Content-Length: 5265 Content-Type: text/html X-Cache: MISS from shade.uchicago.edu Proxy-Connection: keep-alive ----------------------------------------------------------
    And then when I click on the next page, live headers says,
    http://nl.newsbank.com/nl-search/we/Archives/?p_action=list&p_topdoc=1 +1&d_sources=location&p_nbid= GET http://nl.newsbank.com/nl-search/we/Archives/?p_action=list&p_topd +oc=11&d_sources=location&p_nbid= HTTP/1.1 Host: nl.newsbank.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) +Gecko/20050511 Firefox/1.0.4 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Referer: http://nl.newsbank.com/nl-search/we/Archives Cookie: JServSessionIdnewslib=lgfbb4ahn1.JS36b Proxy-Authorization: Basic c2NpY2FsYTphZWRmamtvOw== HTTP/1.x 200 OK Date: Thu, 14 Jul 2005 16:13:27 GMT Server: Apache/1.3.26 (Unix) ApacheJServ/1.1.2 Cache-Control: no-store, no-cache, must-revalidate Expires: Thu, 01 Jan 1970 00:00:00 GMT Pragma: no-cache Content-Type: text/html X-Pad: avoid browser bug X-Cache: MISS from shade.uchicago.edu Proxy-Connection: close ---------------------------------------------------------- http://nl.newsbank.com/nl-search/we/Archives/?p_action=list&p_topdoc=1 +1&d_sources=location&p_nbid= GET http://nl.newsbank.com/nl-search/we/Archives/?p_action=list&p_topd +oc=11&d_sources=location&p_nbid= HTTP/1.1 Host: nl.newsbank.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) +Gecko/20050511 Firefox/1.0.4 Accept: */* Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Referer: http://nl.newsbank.com/nl-search/we/Archives/?p_action=list&p +_topdoc=11&d_sources=location&p_nbid= Cookie: JServSessionIdnewslib=lgfbb4ahn1.JS36b Proxy-Authorization: Basic c2NpY2FsYTphZWRmamtvOw== HTTP/1.x 200 OK Date: Thu, 14 Jul 2005 16:13:33 GMT Server: Apache/1.3.26 (Unix) ApacheJServ/1.1.2 Cache-Control: no-store, no-cache, must-revalidate Expires: Thu, 01 Jan 1970 00:00:00 GMT Pragma: no-cache Content-Type: text/html X-Pad: avoid browser bug X-Cache: MISS from shade.uchicago.edu Proxy-Connection: close ---------------------------------------------------------- http://nl.newsbank.com/favicon.ico GET http://nl.newsbank.com/favicon.ico HTTP/1.1 Host: nl.newsbank.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) +Gecko/20050511 Firefox/1.0.4 Accept: image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Cookie: JServSessionIdnewslib=lgfbb4ahn1.JS36b Proxy-Authorization: Basic c2NpY2FsYTphZWRmamtvOw== HTTP/1.x 404 Not Found Date: Thu, 14 Jul 2005 16:13:36 GMT Server: Apache/1.3.26 (Unix) ApacheJServ/1.1.2 WWW-Authenticate: Basic realm="NewsLibrary" Last-Modified: Mon, 03 Nov 2003 15:41:03 GMT Etag: "d528c-1491-3fa6770f" Accept-Ranges: bytes Content-Length: 5265 Content-Type: text/html X-Cache: MISS from shade.uchicago.edu Proxy-Connection: keep-alive ----------------------------------------------------------
    In my code I post for the first search, get for the next page, and use referer fields on both. But as you can see there is a lot of stuff in the Live Headers that I don't know what it's talking about.
    Any help would be much appreciated.
    Steve