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 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入