PHP:CURL可以跟随元重定向 [英] PHP: Can CURL follow meta redirects

查看:194
本文介绍了PHP:CURL可以跟随元重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

感谢

推荐答案

是的,但是你必须自己通过解析响应来寻找类似的东西:

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/" />

符合< meta> 一个浏览器端的东西。使用DOM解析在响应cURL中查找具有适当属性的< meta> 标记。

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.

如果你能保证响应是有效的XML,你可以这样做:

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

这篇关于PHP:CURL可以跟随元重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆