如何从PHP的curl函数获取最后一个重定向的头? [英] How to get the headers from the last redirect with PHP's curl functions?

查看:148
本文介绍了如何从PHP的curl函数获取最后一个重定向的头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我执行一个设置为跟随重定向并返回标头的cURL请求,它将返回所有重定向的标头。

If I execute a cURL request that is set to follow redirects and return the headers, it returns the headers for ALL of the redirects.

我只想要最后一个返回的头(和内容体)。如何实现?

I only want the last header returned (and the content body). How do I achieve that?

推荐答案

在输出中搜索HTTP / 1.1 200 OK是您最后一个请求开始的地方。所有其他人都会提供其他HTTP回传码。

Search the output for "HTTP/1.1 200 OK" in the beginning of the line - this is where your last request will begin. All others will give other HTTP return codes.

这篇关于如何从PHP的curl函数获取最后一个重定向的头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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