CURLOPT_NOBODY选项在不存在的文件上返回意外的HTTP代码200 [英] CURLOPT_NOBODY option returns unexpected HTTP code 200 on non-existing file
问题描述
我有一个服务器,在这个例子中, install64-7
,我将访问检查是否存在一个zip文件,而不是在服务器上。以下PHP代码返回HTTP返回码 200
,即使该zip文件在服务器 install64-7
上不存在。
I have a server, called install64-7
in this example which I will access to check for the existance of a zip file, which is not on server. The following PHP code returns the HTTP returncode 200
even if the zip file does not exist on the server install64-7
.
$srcPath = "http://install64-7/TestApp.zip";
$ch = curl_init( $srcPath );
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_exec( $ch );
$retcode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
unset( $ch );
var_dump($retcode);
exit;
如果我删除了 CURLOPT_NOBODY
选项, code> 404 !请参阅第二个请求的屏幕截图
In case I remove the option CURLOPT_NOBODY
, the request gives a 404
! see screenshot for second request
$srcPath = "http://install64-7/TestApp.zip";
$ch = curl_init( $srcPath );
//curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_exec( $ch );
$retcode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
unset( $ch );
var_dump($retcode);
exit;
这怎么可能,我失踪了什么?这个术语是关于选项 CURLOPT_NOBODY
的吗?
谢谢任何帮助
How is this possible, what am I missing? What is this sorcery about the option CURLOPT_NOBODY
?
Thank you for any help
推荐答案
CURLOPT_NOBODY设置为TRUE会产生HTTP HEAD请求, HTTP GET。
CURLOPT_NOBODY set to TRUE makes a HTTP HEAD request, as compared to the "normal" HTTP GET.
如果你得到一个不同的repsonse代码,因为它只是因为服务器决定不同的响应 - 虽然它不应该根据HTTP规范。
If you get a different repsonse code because of that it is simply because the server decides to respond differently - although it shouldn't according to the HTTP spec.
这篇关于CURLOPT_NOBODY选项在不存在的文件上返回意外的HTTP代码200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!