CURLOPT_NOBODY选项,返回HTTP意外code 200上不存在的文件 [英] CURLOPT_NOBODY option returns unexpected HTTP code 200 on non-existing file
问题描述
我有一个服务器,名为 install64-7
在这个例子中,我将访问检查zip文件是否存在等,这是不是在服务器上。下面的PHP code返回HTTP返回code 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
,要求给出了一个 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 code - 虽然它不应该根据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意外code 200上不存在的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!