简体   繁体   English

如何使用cURL登录并获取重定向页面

[英]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 我正在尝试使用cURL和SimpleHtmlDom发布一个13位数值并从该站点提取一些数据: 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= 在发布一个13位数值后,我希望得到这个重定向页面: http ://www.hcad.org/records/details.asp?crypt =%94%9A%B0%94%BPg%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&标签=

on which i will apply simplehtmldom to parse some data 我将在其上应用simplehtmldom来解析一些数据

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. 您需要为CURLOPT_FOLLOWLOCATION设置CURLOPT_FOLLOWLOCATION选项以遵循重定向,或者只返回页面数据(如果有)而不重定向。

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 ). 您应该已经发布到表单提交的页面(参见上面的$urltopost )。 Also, you should use a query string as your post data. 此外,您应该使用查询字符串作为发布数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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