【问题标题】:PHP: Can CURL follow meta redirectsPHP:CURL 可以跟随元重定向
【发布时间】:2010-12-21 16:46:43
【问题描述】:

CURL 可以使用 CURLOPT_FOLLOWLOCATION 跟随标头重定向,但是否可以跟随元刷新重定向?

谢谢

【问题讨论】:

    标签: php redirect curl meta-tags


    【解决方案1】:

    是的,但您必须自己通过解析响应并查找类似内容来完成:

    <meta http-equiv="refresh" content="5;url=http://example.com/" />
    

    遵守&lt;meta&gt; 刷新请求是浏览器端的事情。使用 DOM 解析在 cURL 为您提供的响应中查找具有适当属性的 &lt;meta&gt; 标记。

    如果您可以保证响应是有效的 XML,您可以执行以下操作:

    $xml = simplexml_load_file($cURLResponse);
    $result = $xml->xpath("//meta[@http-equiv='refresh']");
    // Process the $result element to get the relevant bit out of the content attribute
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-05
      • 2020-04-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多