您好,欢迎访问一九零五行业门户网

php curl 输出不完整怎么办

php curl输出不完整的解决办法:1、打开相应的php代码文件;2、增加配置为“curl_setopt($ch, curlopt_httpheader, array('expect:'));”;3、封装方法为“function req_curl($url, &$status = null, $options = array()){...}”即可。
本教程操作环境:windows7系统、php8.1版、dell g3电脑。
php curl 输出不完整?php获取数据 curl获取不完整?
因为,php curl库默认1024字节的长度不等待数据的返回,所以你那段代码需增加一项配置:
curl_setopt($ch, curlopt_httpheader, array('expect:'));
给你一个更全面的封装方法:
function req_curl($url, &$status = null, $options = array()){$res = '';$options = array_merge(array('follow_local' => true,'timeout' => 30,'max_redirects' => 4,'binary_transfer' => false,'include_header' => false,'no_body' => false,'cookie_location' => dirname(__file__) . '/cookie','useragent' => 'mozilla/4.0 (compatible; msie 6.0; windows nt 5.1','post' => array() ,'referer' => null,'ssl_verifypeer' => 0,'ssl_verifyhost' => 0,'headers' => array('expect:') ,'auth_name' => '','auth_pass' => '','session' => false) , $options);$options['url'] = $url;$s = curl_init();if (!$s) return false;curl_setopt($s, curlopt_url, $options['url']);curl_setopt($s, curlopt_httpheader, $options['headers']);curl_setopt($s, curlopt_ssl_verifypeer, $options['ssl_verifypeer']);curl_setopt($s, curlopt_ssl_verifyhost, $options['ssl_verifyhost']);curl_setopt($s, curlopt_timeout, $options['timeout']);curl_setopt($s, curlopt_maxredirs, $options['max_redirects']);curl_setopt($s, curlopt_returntransfer, true);curl_setopt($s, curlopt_followlocation, $options['follow_local']);curl_setopt($s, curlopt_cookiejar, $options['cookie_location']);curl_setopt($s, curlopt_cookiefile, $options['cookie_location']);if (!empty($options['auth_name']) && is_string($options['auth_name'])){curl_setopt($s, curlopt_userpwd, $options['auth_name'] . ':' . $options['auth_pass']);}if (!empty($options['post'])){curl_setopt($s, curlopt_post, true);curl_setopt($s, curlopt_postfields, $options['post']);//curl_setopt($s, curlopt_postfields, array('username' => 'aeon', 'password' => '111111'));}if ($options['include_header']){curl_setopt($s, curlopt_header, true);}if ($options['no_body']){curl_setopt($s, curlopt_nobody, true);}if ($options['session']){curl_setopt($s, curlopt_cookiesession, true);curl_setopt($s, curlopt_cookie, $options['session']);}curl_setopt($s, curlopt_useragent, $options['useragent']);curl_setopt($s, curlopt_referer, $options['referer']);$res = curl_exec($s);$status = curl_getinfo($s, curlinfo_http_code);curl_close($s);return $res;}
推荐学习:《php视频教程》
以上就是php curl 输出不完整怎么办的详细内容。
其它类似信息

推荐信息