CURL可以使用CURLOPT_FOLLOWLOCATION跟踪标题重定向,但是可以遵循元刷新重定向吗?

由于

有帮助吗?

解决方案

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

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

Obeying <meta>刷新请求是浏览器方面的事情。使用DOM解析在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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top