curl returntransfer为空,curl_getinfo“错误:1”

时间:2015-10-09 06:07:33

标签: php curl

I try to get a page with curl from an IIS-Server which demands user authentication.

After execution it return null string. The script as given below.

$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, base_url().'forum/heathhandler.php');
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        $string = 'submit=1&action='.$action;
        if($data) {
            $string .= '&data='.$data;
        }

        curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//      curl_setopt($ch, CURLOPT_HEADER, true);
                //curl_setopt($ch, CURLOPT_VERBOSE, true);
        $result = curl_exec( $ch );     

        curl_close($ch);
        return $result;

脚本输出如下所示

数组([url] => http://192.168.4.45/matrix/forum/heathhandler.php [content_type] => text / html; charset = UTF-8 [http_code] => 200 [header_size] => 402 [request_size] =&gt ; 445 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.422 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => ; 0 [size_upload] => 294 [size_download] => 0 [speed_download] => 0 [speed_upload] => 206 [download_content_length] => 0 [upload_content_length] => 294 [starttransfer_time] => 1.422 [redirect_time] => 0 [redirect_url] => [primary_ip] => 192.168.4.45 [certinfo] =>数组()[primary_port] => 80 [local_ip] => 192.168.4.45 [local_port ] => 53506)错误:1

1 个答案:

答案 0 :(得分:0)

要通过基本身份验证

curl_setopt($process, CURLOPT_HTTPHEADER, 
             array('Content-Type: application/xml', $additionalHeaders));
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);