卷曲在PHP返回即使网址正在404响应代码(Curl in php returns 404 resp

2019-10-20 17:21发布

我使用PHP 5.4中的CentOS 6.5

我想获得响应代码的下方的网址是我的代码片段

$URL="http://www.bertuccis.com/#menu";
try{

    $c = curl_init();
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36');
    curl_setopt($c, CURLOPT_URL, $URL);
    $contents = curl_exec($c);
    $httpCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
    curl_close($c);

    echo 'Resp Code ' . $httpCode;
} catch(Exception $ex){
    print_r($ex);
}

它返回404 HTTP响应代码。 如果我在浏览器尝试相同的URL,则返回200 OK。

我试图用我的CentOS的机器,但其工作的终端卷曲-v

这里是卷曲和PHP卷曲的版本信息

卷曲在我的CentOS的lib是:卷曲7.24.0(x86_64的未知-Linux的GNU)的libcurl / 7.24.0

PHP的卷曲在我的PHP信息的信息:

cURL support => enabled
cURL Information => 7.19.7
Age => 3
Features
AsynchDNS => No
Debug => No
GSS-Negotiate => Yes
IDN => Yes
IPv6 => Yes
Largefile => Yes
NTLM => Yes
SPNEGO => No
SSL => Yes
SSPI => No
krb4 => No
libz => Yes
CharConv => No
Protocols => tftp, ftp, telnet, dict, ldap, ldaps, http, file, https, ftps, scp, sftp
Host => x86_64-redhat-linux-gnu
SSL Version => NSS/3.15.3
ZLib Version => 1.2.3
libSSH Version => libssh2/1.4.2

Answer 1:

这是卷曲的错误和(根据该网页固定在7.28.1 http://curl.haxx.se/changes.html )。

注:现代浏览器在犯规请求发送片段组成部分。 但是,你的卷发发吧,这是使差异。



文章来源: Curl in php returns 404 response code even if url is working