Php – CURLOPT_NOBODY influence the response header when i use curl

curlhttp-headersPHP

my problem code

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.tudou.com/programs/view/qyT7G6gVFSs');
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl , CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
var_dump($data);

the response is

string(241) "HTTP/1.1 405 Method Not Allowed
Server: Tengine/1.4.0
Date: Sat, 01 Dec 2012 15:53:32 GMT
Content-Type: text/html;charset=GBK
Content-Length: 1085
Connection: close
appSrv: itemview-app4-app_admin
Vary: Accept-Encoding
Allow: GET
"

then my correct code is

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.tudou.com/programs/view/qyT7G6gVFSs');
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
var_dump($data);

the result is
string(313) "HTTP/1.1 302 Moved Temporarily
Server: Tengine/1.4.0
Date: Sat, 01 Dec 2012 16:17:25 GMT
Content-Length: 0
Connection: close
appSrv: itemview-app5-app_admin
Vary: Accept-Encoding
Pragma: No-Cache
Cache-Control: no-cache, no-store
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: http://tv.tudou.com/

"

yes it's just the CURLOPT_NOBODY,anybody can tell me why?please!

Best Answer

When you specify a CURLOPT_NOBODY, it actually performs a different type of request Does CURLOPT_NOBODY still download the body - using bandwidth It looks like the server you are curling against does not support this type of request.

Related Topic