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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题