PHP: Can CURL follow meta redirects

一个人想着一个人 提交于 2019-11-26 18:35:40

问题


CURL can follow header redirects with the use of CURLOPT_FOLLOWLOCATION but is it possible to follow meta refresh redirects?

Thanks


回答1:


Yes, but you'll have to do it yourself by parsing the response and looking for things that look like:

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

Obeying <meta> refresh requests is a browser-side thing. Use DOM parsing to look for <meta> tags with the appropriate attributes in the response cURL gives you.

If you can guarantee that the response is valid XML, you could do something like this:

$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


来源:https://stackoverflow.com/questions/1820705/php-can-curl-follow-meta-redirects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!