CURL 可以使用 CURLOPT_FOLLOWLOCATION 跟随标头重定向,但是否可以跟随元刷新重定向?
谢谢
是的,但是您必须自己通过解析响应并查找如下内容来完成:
<meta http-equiv="refresh" content="5;url=http://example.com/" />
服从<meta>
刷新请求是浏览器端的事情。使用 DOM 解析<meta>
在 cURL 为您提供的响应中查找具有适当属性的标签。
如果您可以保证响应是有效的 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