【问题标题】:CURL Post values not workingCURL Post 值不起作用
【发布时间】:2011-11-28 09:05:11
【问题描述】:

使用下面的脚本,我尝试登录网页,然后执行通常由按钮后面的 Ajax 脚本触发的帖子。登录工作正常,但我无法模拟 Ajax 操作。感谢您的帮助

<?php  
ini_set('max_execution_time', 0);     
$submit_url = "LOGINURL"; 

$submit_url2 = "OVERVIEWURL";   
$postdata = array('action.id' => urlencode('al_regid_162'), 
                    'action.component.id' => urlencode('form_aanvraag_filter'), 
                    'action.section.id' => urlencode('section1')); 

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ; 
curl_setopt($curl, CURLOPT_USERPWD, "USERNAME:PASSWORD"); 
curl_setopt($curl, CURLOPT_SSLVERSION,3); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($curl, CURLOPT_HEADER, false);       
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);     
curl_setopt($curl, CURLOPT_URL, $submit_url); 
$data = curl_exec($curl); 

curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt($curl, CURLOPT_URL, $submit_url2); 
$data = curl_exec($curl);

print($data);



curl_close($curl);    
?>

【问题讨论】:

  • 你有什么类型的错误?
  • 您好,Oyeme,我没有收到错误消息。我没有收到预期的数据,因为我认为 Ajax 按钮按下模拟不正确。
  • 好吧,你不能用 curl 模拟 ajax 点击。使用“httplifeheader”你可以看到参数和 wich 方法用于 ajax。(POST 或 GET)。
  • 是的,我搜索了这个并找到了以下内容:WEBPAGE/pimplus/service/…
  • 如何在脚本中添加这个?我想尝试,但由于登录,我不确定在哪里添加 get_contents

标签: php post curl


【解决方案1】:
  1. 1.在 curl 脚本中将 CURLOPT_FOLLOWLOCATION 设置为 true。

  2. 在 curl 代码后使用file_get_contents('your_url/WEBPAGE/pimplus/service');。(仅适用于 GET 方法)

【讨论】:

  • if(!file_get_contents('WEBPAGE/pimplus/service/…)) { echo "Error";将它放在 CURL 代码后面会导致错误。
  • 尝试将此网址放到浏览器栏。我认为您的参数无效。
  • 有效吗? file_get_contents('google.com'); //完整的谷歌网址
  • 原始链接的错误是以下打开流失败:HTTP请求失败! HTTP/1.1 401 Unauthorized requesting google 导致以下结果: failed to open stream: 连接尝试失败,因为连接的一方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应
  • $context = stream_context_create(array( 'http' => array( 'header' => "授权:基本 " .base64_encode("$username:$password"). "\r\n" . "Cookie: action.id=al_regid_162; action.component.id=form_aanvraag_filter; action.section.id=section1; field.aanvraag.filter.status=open; field.aanvraag.filter.sortering=AAVRAAGID\r\n" ) )); $data = file_get_contents($url, false, $context);回显$数据;这段代码将我带到了 Curl 中,结果完全相同。任何想法如何发送值?
【解决方案2】:

尝试做:

curl_setopt($ch,CURLOPT_URL,$submit_url2); curl_setopt($ch,CURLOPT_POST,count($postdata)); curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);

希望对你有帮助

【讨论】:

  • 嗨 Sudhir,很遗憾,这并不能解决问题。还有其他想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-15
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多