Hi all,

  I'm having some problems getting cookies from a POST request, and need
some help from the PERL gurus. Let's describe the problem first.

  I'm trying to make a script to post e-Mail notifications to the SMS
web engine of my Mobile Phone provider (BCP -
http://www.bcp.com.br/digimemo). The problem is that it seems that the
guys at BCP don't want us to do it, so they created a set of 3 scripts
to avoid us from posting right to the SMS engine. The whole thing works
like this:

  1st Script.
  When you access the first .asp page (main form) they have the form
fields and a hidden field with some sort of check number (field
CALCULO). In this page they also set a cookie that is requested in the
second script.

  2nd Script. 
  Receives the 1st Script data, get the cookie, generates another form
with all the information from the first script as hidden fields and a
new CALCULO field, and set a NEW cookie. This page has a Javascript
activated by the ONLOAD event to auto submit the form to the 3rd Script.

  3rd Script
  Receives the 2nd Script data, get the cookie, sends the SMS message,
writes a "Your message was sent" page. Game Over :)



  
My script is getting the CALCULO field aand the cookie from the 1st
Scriptt, and POSTing my data  to the 2nd Script, and here is the
problem. I can't get the 2nd Script Cookie. It seems to me that the POST
method doesn't sets the '_set_cookie' field in the Response object.

   Here are the parts of the script that handle the cookies:


#Global Var
$cookie_jar = HTTP::Cookies->new;

# To handle the 1st Script I use the gettoken sub.

sub gettoken {
   my $tokenurl = shift;
   my $ua = new LWP::UserAgent;
   my $req = new HTTP::Request 'GET', $tokenurl;
   my $res = $ua->request($req);

   $cookie_jar->extract_cookies($res);

   ...
   More Code
   ...

}

# This sub handles the posting of the e-mail data and the CALCULO field
to the 2nd script, and 
# colects the 2nd cookie.

sub post2server1 {
   my $postto = shift;
   my $content = shift;
   my $ua = new LWP::UserAgent;
   my $req = new HTTP::Request 'POST', $postto;

   $cookie_jar->add_cookie_header($req);
   $req->content_type('application/x-www-form-urlencoded');
   $req->content($content);
   my $res = $ua->request($req);
   $cookie_jar->extract_cookies($res);

   ...
   More Code
   ...

}

   The problem seem to be in the $cookie_jar->extract_cookies($res);
line. It simply doen't get the cookie. Using the PERL debugger I found
that the $res->_header->_set_cookie is not set in the post2server1 sub
but it IS SET to in the gettoken sub.


   Thanks in advance for any clue on my problem.



   Yours,

   Norival Toniato Junior


PS: If you are going to reply this message please CC it to my address
([EMAIL PROTECTED]) since I'm not subscribed to the libwww list. Thank
You.

Reply via email to