Preexo
Preexo

Reputation: 2142

CURLOPT_NOBODY option returns unexpected HTTP code 200 on non-existing file

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;

enter image description here

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;

enter image description here

How is this possible, what am I missing? What is this sorcery about the option CURLOPT_NOBODY? Thank you for any help

Upvotes: 0

Views: 927

Answers (1)

Daniel Stenberg
Daniel Stenberg

Reputation: 58214

CURLOPT_NOBODY set to TRUE makes a HTTP HEAD request, as compared to the "normal" HTTP GET.

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.

Upvotes: 3

Related Questions