Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中使用Curl单击按钮并获得响应_Php_Curl - Fatal编程技术网

在PHP中使用Curl单击按钮并获得响应

在PHP中使用Curl单击按钮并获得响应,php,curl,Php,Curl,我试图将我们的页面链接到另一个页面,但它位于免责声明警告的另一侧。在所有人都对我试图做一些不道德的事情表示不满之前,我只是想让我的用户更容易地访问到一个页面——我不是在抓取任何信息或做一些不光彩的事情 我遇到的问题是: 我正试图按下此按钮: <input type="submit" name="Answer" value="Accept"\> 以下是我的php/curl代码: $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0;

我试图将我们的页面链接到另一个页面,但它位于免责声明警告的另一侧。在所有人都对我试图做一些不道德的事情表示不满之前,我只是想让我的用户更容易地访问到一个页面——我不是在抓取任何信息或做一些不光彩的事情

我遇到的问题是:
我正试图按下此按钮:

<input type="submit" name="Answer" value="Accept"\>

以下是我的php/curl代码:

$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)"; 
$url = 'https://www.bcpao.us/asp/disclaimap.asp';
$ckfile = tempnam ("d:/temp", "CURLCOOKIE");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data['Answer'] = "Accept";
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// I have tried the following also:
// curl_setopt($ch, CURLOPT_POSTFIELDS, "Submit=Answer%Accept");


$output=@curl_exec($ch);
$info = @curl_getinfo($ch);

if(curl_errno($ch)){
  echo 'Curl error: ' . curl_error($ch);
}

curl_close($ch);
echo "output is:'" . $output . "'";
echo "<br>";
echo "info is:";
print_r($info);
$agent=“Mozilla/5.0(Windows;U;Windows NT 5.0;en-US;rv:1.4)Gecko/20030624 Netscape/7.1(ax)”;
$url='1https://www.bcpao.us/asp/disclaimap.asp';
$ckfile=tempnam(“d:/temp”、“CURLCOOKIE”);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_COOKIEJAR,$ckfile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
$data['Answer']=“接受”;
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
//我还尝试了以下方法:
//curl_setopt($ch,CURLOPT_POSTFIELDS,“Submit=Answer%Accept”);
$output=@curl\u exec($ch);
$info=@curl\u getinfo($ch);
if(旋度误差($ch)){
回显“旋度误差:”。旋度误差($ch);
}
卷曲关闭($ch);
echo“输出为:”$输出。"'";
回声“
”; 回声“信息是:”; 打印(信息);

当我运行脚本时,我将返回原始页面(而不是按钮链接的页面)。任何帮助都将不胜感激

查看
表单
标签:

<form action="answer_disclaimap.asp" method="post" id="Form1">
和使用:


好吧,你的办法很有效,但我没有达到我的预期。一旦您接受了他们的条款,无论何时您(作为普通用户)浏览他们的网站,URL中都有一个ID=“some number”。这个数字会持续一段时间,但最终会超时(有点像cookie),所以我假设这个数字会出现在cookie文件中,但它不会。。。有什么建议吗?。。。没关系-在查看了返回页的源html之后,我发现它又被埋没了-盎司,谢谢你抓住了我之前的错误:-)
$url = 'https://www.bcpao.us/asp/answer_disclaimap.asp';
$data['Answer'] = "Accept";
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($data) );