简体   繁体   中英

how to login and get the redirected page using cURL

I am trying to use cURL and SimpleHtmlDom to post a 13-digit value and pull some data from this site : http://www.hcad.org/records/Real.asp?search=acct

After posting a 13-digit value i want to get this redirected page : http://www.hcad.org/records/details.asp?crypt=%94%9A%B0%94%BFg%85%8E%84%82pg%8El%88tXt%5FW%9E%99%A2%D3%89%95%C2e%7CU%8A%7D%86%C0%AB%A8%AD%86%5E&bld=1&tab=

on which i will apply simplehtmldom to parse some data

i have searched some site to make this code snippet

<?php
$urltopost = "http://www.hcad.org/records/Real.asp?search=acct";
$datapost = array(
"searchval" => "1158830010007",
);
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($ch);
echo $returndata;
?>

but its not providing me the redirected page i want . what should i do now to do it correctly ?? waiting for any kind of help .

Thanks in advance

You need to set the CURLOPT_FOLLOWLOCATION option for the curl to follow a redirect or it just returns the page data (if any) without redirecting.

curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );

Edit : I have looked at the source code on the page, you should modify your code accordingly:

$urltopost = "http://www.hcad.org/records/SelectRecord.asp";
$datapost = "searchval=1158830010007&TaxYear=2011&searchtype=strap";

You should have been posting to the page that the form submits to (see above $urltopost ). Also, you should use a query string as your post data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM