使用PHP Curl获取404但可以访问URL

时间:2016-02-23 14:38:42

标签: php curl

我尝试使用curl从特定网站获取数据,并获得404响应。奇怪的是,我可以很好地访问网址。

我想问题出在其他地方(很可能是因为我的格式错误的请求开始)并且想知道是否有人可以解释一下:

    ...
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_USERAGENT, 'my own agent');
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_URL, $url);
    if (! empty($data)) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'c4l.cookie');
    $output['returned'] = curl_exec($ch);
    $output['info'] = curl_getinfo($ch);

    return $output;
PS:上面的代码不是由我编写的,也不是我用PHP编写的,但我需要调试并查找导致错误的任何内容。

非常感谢任何帮助。

编辑:

网址为:http://www.example.com/something/else/here.also

EDIT2:

实际回应是:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL /something/else/here.also was not found on this server.<P>
<HR>
<ADDRESS>Oracle-Application-Server-10g/10.1.3.5.0 Oracle-HTTP-Server     Server at cbl08901app01.nat.bt.com Port 61000</ADDRESS>
</BODY></HTML>

0 个答案:

没有答案