卷曲一段时间给空白输出

时间:2019-05-18 04:47:11

标签: php curl

我一直在使用curl来获取站点的特定数据,但有时它会为空白数据提供空白输出

function ftch($url,$post="", $ck = 'cookie.dat')
{
    $ver   = rand(4, 6);
    $agent = 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) 
    AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile 
    Safari/537.36';
    $ch    = curl_init();
    curl_setopt($ch, CURLOPT_URL, '' . $url . '');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_COOKIESESSION, 'cookie.s');
    curl_setopt($ch, CURLOPT_COOKIEJAR, $ck);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $ck);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    //     'Accept-Language: en-us,en;q=0.7,de-de;q=0.3',
    //     'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
    // ));
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;
}

请正确设置代码格式

0 个答案:

没有答案