【问题标题】:Curl returntransfer is empty, curl_getinfo “Error: 1”curl 回传为空,curl_getinfo “Error: 1”
【发布时间】:2015-10-09 06:07:32
【问题描述】:
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] => 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] => Array () [primary_port] => 80 [local_ip] => 192.168.4.45 [local_port] => 53506) 错误:1

【问题讨论】:

  • 您将如何绕过所需的身份验证?

标签: php curl


【解决方案1】:

要通过基本身份验证,您可以

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-06
    相关资源
    最近更新 更多