2
votes

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!

2

2 Answers

1
votes

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.

0
votes

Try to do something like this:

            //cURL set options
            //cURL options array set
            $options = array(
                CURLOPT_URL => $this->URL,              #set URL address
                CURLOPT_USERAGENT => $this->UserAgent,  #set UserAgent to get right content like a browser
                CURLOPT_RETURNTRANSFER => true,         #redirection result from output to string as curl_exec() result
                CURLOPT_COOKIEFILE => 'cookies.txt',    #set cookie to skip site ads
                CURLOPT_COOKIEJAR => 'cookiesjar.txt',  #set cookie to skip site ads
                CURLOPT_FOLLOWLOCATION => true,         #follow by header location
                CURLOPT_HEADER => true,                 #get header (not head) of site
                CURLOPT_FORBID_REUSE => true,           #close connection, connection is not pooled to reuse
                CURLOPT_FRESH_CONNECT => true,          #force the use of a new connection instead of a cached one
                CURLOPT_SSL_VERIFYPEER => false         #can get protected content SSL
            );
            //set array options to object $curl
            curl_setopt_array($curl, $options);