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

查看:29
本文介绍了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/" />

遵守 刷新请求是浏览器端的事情.使用 DOM 解析在 cURL 为您提供的响应中查找具有适当属性的 标记.

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天全站免登陆