Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

My program needs to enter a web page, get a session number (which is stored in a cookie), and then go to a subsequent page on the same site using that cookie to maintain the session.

I thought this would be simple, using HTTP::Cookies to create a cookie jar. After beating my head against it for a while, I realized that the site was not passing me any set-cookies in the header. But when I visit the page from a browser, and I tell the browser to prompt me if a cookie arrives, the browser tells me the site is sending me cookies.

I even telneted to the site on port 80, and got the same header information with no set-cookies

I distilled the code down to the following. I check two sites, the one which doesn't send me cookies in the header (infojobs) and one which does (msn).

Has anyone seen this before? How are they sending me cookies if they aren't in the header?

# - print out headers of various URLs use strict; use LWP::UserAgent; my @urls; # Create array of URLs to visit push(@urls,""); push(@urls,""); # Create user agent which emulates Internet Explorer my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/4.0 (Compatable; MSIE 5.01; Windows NT 5.0)'); # Cycle through URLs and print out their headers for my $url (@urls) { my $request; my $result; # Create a request object for this URL $request = HTTP::Request->new('GET', $url); $request->header('Accept' => 'text/html'); # Submit the request $result = $ua->request($request); # Print the resulting header print "_" x 80 ."\n"; print "Looking up $url...\n"; print $result->headers_as_string; }

In reply to LWP::UserAgent doesn't see cookies in header by zeno

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-12-11 05:29 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (41 votes). Check out past polls.