CURL可以使用CURLOPT_FOLLOWLOCATION跟随头部重定向,但是否可以跟随meta refresh重定向呢?谢谢。
可以,但你需要自己解析响应并查找类似于以下内容的内容:
<meta http-equiv="refresh" content="5;url=http://example.com/" />
遵守 <meta>
刷新请求是浏览器端的事情。使用DOM解析在cURL响应中寻找具有适当属性的 <meta>
标签。
如果您可以保证响应是有效的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