PHP获取http头响应代码没有cURL [英] PHP get http header response code without cURL
问题描述
我写了一个类来检测cURL是否可用,如果它使用cURL执行GET,POST,DELETE。在cURL版本中,我使用 curl_getinfo($ curl,CURLINFO_HTTP_CODE);
来获取HTTP代码。如果是cURL不可用,它使用fopen()读取文件内容。如何获取没有cURL的HTTP头代码?
I have written a class that detects if cURL is available, if it is performs GET, POST, DELETE using cURL. In the cURL version I use curl_getinfo($curl, CURLINFO_HTTP_CODE);
to get the HTTP code. If is cURL is not available it uses fopen() to read the file contents. How do I get the HTTP header code without cURL?
推荐答案
每当你做一些HTTP交互时,特殊变量 $ http_response_header
将包含所有标题(包括状态行标头)。
Whenever you do some HTTP interaction, the special variable $http_response_header
on the same scope will contain all headers (incl. the status line header) that are resulted from the last HTTP interaction.
这篇关于PHP获取http头响应代码没有cURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!