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!

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀