dongzanghua8422 2015-05-02 07:27
浏览 268

使用curl_getinfo返回200失败

I use this code to get info about webpages and files before download.

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_NOBODY, 1); 

curl_exec($curl);

if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200)
{ 
    echo $info['active'] = true;
    echo $info['url'] = $url;
    echo $info['size'] =     curl_getinfo($curl,CURLINFO_CONTENT_LENGTH_DOWNLOAD);
    echo $info['type'] = curl_getinfo($curl,CURLINFO_CONTENT_TYPE);

}
else
    echo 'not active';

It works for file or urls format like this:

www.example.com/film.mp4
www.example.com/film.php

but not works without extension name in URL..it return me 'not active';

www.example.com/film
www.example.com/film/test

how can I fixed it?

UPDATE:

it retun 403 error with CURLINFO_HTTP_CODE

  • 写回答

2条回答 默认 最新

  • douzhan1935 2015-05-02 10:43
    关注

    This is not a problem with cURL; the website you are trying to pull data from is returning the 403 when you specify a URL without a file. Try loading those pages yourself in a browser to see.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能