Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I hope I ask this specific enough not to confuse or ask for the wrong answers.

Iam using LWP::useragent and HTTP::request to retreive documents. Now heres my problem:

When I retrieve them and print them to the screen, the document Im accessing also wants to send there own cookies to be set BUT, since Im accessing it thru my script, it seems to be unable to set its cookies.

I need a way to request the document; display the document; at the same time allow the requested documents domain to set these cookies because they are important.

I can't set there cookie so I have to find a way to allow them to set it.
Keep in mind I cannnot access the document without my script so I have to find a way to do it thru CGI.

Thanks.

Edited 2001-05-14 by Ovid. Shortened title. Original title was:

http::request, lwp::useragent, cookie, cookies, retrieve document; print it to screen; and allow them to set there own cookie

Replies are listed 'Best First'.
Re: How can my script accept cookies?
by Daddio (Chaplain) on May 15, 2001 at 05:23 UTC

    Admittedly, I don't have a whole lot of experience with cookies, especially in the manner you are working here. But, to summarize, here is what the LWP::UserAgent has to say about cookies:

    $ua->cookie_jar([$cookies]) # Get/set the HTTP::Cookies object to use. The default # is to have no cookie_jar, i.e. never automatically add # "Cookie" headers to the requests.

    In the LWP CookBook (man lwpcook), I found this (and it has some examples):

    COOKIES Some sites like to play games with cookies. By default LWP ignores cookies provided by the servers it visits. LWP will collect cookies and respond to cookie requests if you set up a cookie jar. use LWP::UserAgent; use HTTP::Cookies; $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt", autosave => 1)); # and then send requests just as you used to do $res = $ua->request(HTTP::Request->new(GET => "http://www.yahoo.no") +); print $res->status_line, "\n"; As you visit sites that send you cookies to keep, then the file lwpcookies.txt" will grow.

    I don't know how much that will help since I can't give you any examples of my own, but I thought I would post it anyway. I have found reading the lwpcook and LWP::UserAgent documentation helpful in what I have done with LWP, so I recommend reading it if you haven't already.

    D a d d i o

Re: How can my script accept cookies?
by stephen (Priest) on May 15, 2001 at 04:48 UTC
    I believe you'll find the answer in your LWP::UserAgent documentation. Look for the 'cookie_jar()' method.

    stephen

Re: How can my script accept cookies?
by cLive ;-) (Prior) on May 15, 2001 at 03:45 UTC
Re: How can my script accept cookies?
by John M. Dlugosz (Monsignor) on May 15, 2001 at 22:47 UTC
    there is the reverse of here. Remember because the words have the same ending. their is the possessive form of they. Remember it as a weird case of change-the-y-to-i.
A reply falls below the community's threshold of quality. You may see it by logging in.