in reply to Re: Re: Re: Cookies from CGI to LWP and back
in thread Cookies from CGI to LWP and back

Sorry for my brief error handling on the list, I should provide more input...
Indead the HTTP::Proxy is what I need but this needs to be implemented in a CGI style. I need to run this scrip on an apache server running CGI. I can not use the HTTP::Proxy for that reason, nor can I use mod_proxy from the apache server. The problem is that the content needs to be modified in the CGI script. So What I try to do (without any luck at thsi moment ;-) is to transform the incomming CGI into a LWP request and change the content of the LWP and send it back to the browser.You can think of this application as a small sceen scrapper, "stealling" pages at an other server and changing this on the fly. All this written in a nice CGI environment.

I have tried your suggestion in a small script :
my $ua = LWP::UserAgent->new;
$ua->agent($q->http('HTTP_USER_AGENT'));

my $cookie_jar = new HTTP::Cookies();
my %cookies = fetch CGI::Cookie;
my $cookie= "";

foreach $cookie (keys %cookies) {
$cookie_jar->set_cookie(1,$cookie->name,$cookie->value,$cookie->path,$cookie->domain,80,'',0,$cookie->expires,0,{});
};

This gives the error ....
Premature end of script headers: /usr/local/apache/cgi-bin/cook.cgi
Can't locate object method "name" via package "SID" (perhaps you forgot to load "SID"?)at /usr/local/apache/cgi-bin/cook.cgi line 47.
I know that SID is the name of one of my cookies, so I must be doing somthing good...
But, I do not understand why it is not working

Any suggestions are welcome,
Thanxs in advance,
Tom
  • Comment on Re: Re: Re: Re: Cookies from CGI to LWP and back

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Cookies from CGI to LWP and back
by Corion (Patriarch) on Apr 14, 2004 at 16:40 UTC

    Ooops - that's an error in my script. I didn't read the documentation closely enough. The loop should be:

    my $name; foreach $name (keys %cookies){ my $cookie = $cookies{$name}; $cookie_jar->set_cookie(1,$cookie->name,$cookie->value,$cookie->path +,$cookie->domain,80,'',0,$cookie->expires,0,{}); };

    I am still not saying that you should use HTTP::Proxy, but you should still look at how it does its thing and steal the parts that you can use. Even if the whole is not what you need, parts of it may still be of use for you or aid you as a learning tool.

    PS: You might want to read Writeup Formatting Tips to see how you can wrap your code in <CODE> tags so it shows up nicely.