我如何获得响应头文件? [英] How can I get the response headers?
本文介绍了我如何获得响应头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用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响应的格式与发送请求基本相同:正文由两个CRLF( \r\\\
)分隔。
\r\\\
The format for receiving a HTTP response is basically the same as for sending a request: headers and body are separated with two CRLF (\r\n\r\n
).
$parts = explode("\r\n\r\n", $http_response);
$headers = array_shift($parts);
$body = implode("\r\n\r\n", $parts);
这篇关于我如何获得响应头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文