如何获取响应标头? [英] How can I get the response headers?

查看:55
本文介绍了如何获取响应标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 PHP CLI 中连接到远程主机并发送一些标头.然后我的脚本等待响应.我可以将其全部打印出来,但随后它会返回 HTML.我只想要标题.我该怎么做?

I'm currently connecting to a remote host in PHP CLI and sending some headers. My script then waits for the response. I can have it all print out, but then it returns the HTML. I only want the headers. How can I do this?

推荐答案

接收HTTP响应的格式与发送请求基本相同:headers和body用两个CRLF( ).

The format for receiving a HTTP response is basically the same as for sending a request: headers and body are separated with two CRLF ( ).

$parts = explode("

", $http_response);
$headers = array_shift($parts);
$body = implode("

", $parts);

这篇关于如何获取响应标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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