cURL响应不同于Web响应

时间:2016-07-05 13:08:22

标签: php html curl load php-curl

我想获得所有页面内容,我有他们的网址

我为获取https://fonts.googleapis.com/css?family=Open+Sans

的内容编写了以下php代码
 function curl_file_get_content($url){
    $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $ch=curl_init();
    curl_setopt_array($ch, [
            CURLOPT_URL=>$url,
            CURLOPT_USERAGENT=>$agent,
            CURLOPT_RETURNTRANSFER=>1,
            CURLOPT_TIMEOUT=>5,
            CURLOPT_VERBOSE=>0,
            CURLOPT_SSLVERSION=>3,
            CURLOPT_SSL_VERIFYPEER=>0,
            CURLOPT_SSL_VERIFYHOST=>0,
        ]);
    $page=curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if($httpcode>=200 && $httpcode<300) return $page;
    else return false;
}
if($content=curl_file_get_content("https://fonts.googleapis.com/css?family=Open+Sans")){
    echo $content;
}else{
    echo "the Website is DOWN" ;
}

输出是以下代码

@font-face {
  font-family: 'Open Sans';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/opensans/v13/cJZKeOuBrn4kERxqtaUH3fY6323mHUZFJMgTvxaG2iE.eot);
}

如果您查看网址https://fonts.googleapis.com/css?family=Open+Sans,您会注意到此页面的内容和我的代码输出是不正确的,我的代码输出是该页面的一部分

但此代码可正常用于获取localhost文件的内容

问题是什么? 我可以获得这个页面的全部内容吗?

1 个答案:

答案 0 :(得分:3)

它是您使用过的用户代理,当我将其设置为git show时,它似乎会返回完整的内容。

w
相关问题