我目前正在 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);
这篇关于如何获取响应标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!