我的问题代码
<?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);回应是
字符串(241) "HTTP/1.1 405方法不允许服务器: Tengine/1.4.0日期: Sat,01 Dec 2012 15:53:32 GMT Content-Type: text/html;charset=GBK Content-Length: 1085连接:关闭appSrv: itemview-app4-app_admin Vary: Accept-Encoding Allow: GET“
那么我的正确代码是
<?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);结果是字符串(313)“HTTP/1.1302临时移动服务器: Tengine/1.4.0日期: Sat,01 Dec 2012 16:17:25GMT Content-Length: 0 Connection: close appSrv: itemview-app5-app_admin Vary: Accept-Encoding Pragma: No- Cache -Control: no-cache,no-store Expires:清华,1970年1月1日00:00:00GMT位置:http://tv.tudou.com/
“
是的,这只是CURLOPT_NOBODY,谁能告诉我为什么?请!
发布于 2012-12-02 00:26:27
当您指定一个CURLOPT_NOBODY时,它实际上执行一个不同类型的请求Does CURLOPT_NOBODY still download the body - using bandwidth它看起来像是您所针对的服务器不支持这种类型的请求。
发布于 2012-12-02 00:28:35
试着这样做:
//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);https://stackoverflow.com/questions/13661223
复制相似问题