So i am still trying to get the result page of a webpage, which has a captcha request in between the form and the result page. For that, I first download the form with the GET method, then POST my form input, which leads to a captcha request. By then, i want to submit the captcha solution and send it away with "POST" again. But once it's submitting, the webpage generates a new cookie (e.g a new JSESSIONID ), but in my perl script the cookie remains the same. That's also the reason why i won't get to the actual result page. So how could i get the current cookie too? Any help is highly appreciated.
my $ua = LWP::UserAgent->new( verify_hostname => 0); #downloading the form: $ua->cookie_jar($cookie_jar); $ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; In +foPath.1; .NET CLR 2.0.50727)'); my $url = www.anywebsite.com my $response = $ua->get($url); die "Couldn't get $url", $response->status_line unless $response->is_ +success; #submitting the form: $keyword = "asdsa"; $Search_url ="www.wheretosubmit.com"; $param = 'showType=1&strSources=&strWhere='.$strWhere.'&numSortMethod= +&strLicenseCode=&numIp=&numIpc=&numIg=&numIgc=&numIgd=&numUg=&numUgc= +&numUgd=&numDg=&numDgc=&pageSize=3&pageNow=1'; $request = HTTP::Request->new('POST', $Search_url); $request->header('Content-Type' => 'application/x-www-form-urlencoded' +); $request->header('Referer' => "www.webpage.com"); $request->header('Accept' => 'text/html,application/xhtml+xml,applicat +ion/xml;q=0.9,*/*;q=0.8'); $request->header('Connection' => 'keep-alive'); $request->content($param); $response = $ua->request($request); $page = $response->decoded_content(); #parsing $page to catch the captcha image and get the user recognition ... #trying to send captcha text away: while(defined($captcha)){ $param="numIg=&numDgc=&numIgc=&numIp=&pageSize=20&strWhere='.$strWhere +.'&numDg=&numIpc=&numUgc=&numUgd=&strLicenseCode=&numIgd=&showType=1& +numSortMethod=&strSources=&numUg=&pageNow=1&vct='.$captcha.'&Submit=% +E7%BB%A7%E7%BB%AD"; $Search_url ="www.webpage.com"; $request = HTTP::Request->new('POST', $Search_url); $request->header('Host' => 'www.webpage.com' ); $request->header('Accept' => 'text/html,application/xhtml+xml,applicat +ion/xml;q=0.9,*/*;q=0.8'); $request->header( 'Referer' => "www.webpage.action"); $request->header('Connection' => 'keep-alive'); $request->content($param); $response = $ua->request($request); $page = $response->decoded_content(); ##instead of accepting the captcha submit and leading on the result pa +ge, the webpage reload ( and just to another captcha)

In reply to LWP Cookies by amitsq

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.