duanhui1869 2011-11-01 23:58
浏览 67
已采纳

curl获取重定向网页的内容

I try to login in a site which has a combined login.

The redirect to this site works fine and the redirect back as well ... but only if I stop the PHP programm with die(). Unfortunately it is not stored in $return, which I would need to proceed.

Any ideas, what I am doing wrong? Much appreciated!

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,    FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,    FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,    TRUE);
curl_setopt($ch, CURLOPT_POST,              TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,    TRUE);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, TRUE);
curl_setopt($ch, CURLOPT_POSTREDIR,         TRUE);

curl_setopt($ch, CURLOPT_URL,               URI_LOGIN);

$content = curl_exec($ch);

// PREPARING THE LOGIN
$referer = URI_LOGIN . '?ReturnUrl=' . urlencode('/returnUrl/');

curl_setopt($ch, CURLOPT_URL,         $referer);
curl_setopt($ch, CURLOPT_REFERER,     $referer);

curl_setopt($ch, CURLOPT_COOKIEJAR,   COOKIE);

$post = ...;
curl_setopt($ch, CURLOPT_POSTFIELDS,  http_build_query($post) );

curl_setopt($ch, CURLOPT_USERAGENT,   '...');
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);

$content = curl_exec($ch);

// LOGIN 
curl_setopt($ch, CURLOPT_URL, COMBINED_LOGIN);

$post = ...;

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post) );

$return = curl_exec($ch);

// ...
?>
  • 写回答

1条回答 默认 最新

  • donglei2022 2011-11-02 19:08
    关注

    There was a problem with javascript. It stucked on an 'in-between'-page and I had to make another curl request to get to the right page.

    Now it is working fine!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!