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

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)

Replies are listed 'Best First'.
Re: LWP Cookies
by dbander (Scribe) on Aug 01, 2017 at 02:02 UTC

    I would not expect a Captcha response to want a new page, so your second

    $request = HTTP::Request->new('POST', $Search_url);

    is probably the culprit here.

    I'm curious; are you attempting to perform automated testing or something?