使用curl阅读内容

时间:2011-01-22 00:10:44

标签: php curl

使用Curl我正在向服务器发送一些帖子数据。这是我得到的标题响应

HTTP / 1.1 100继续HTTP / 1.1 200 OK内容长度:30内容类型:text / html; charset = ISO-8859-1服务器:Microsoft-IIS / 7.0 X-Powered-By:Servlet 2.5; JBoss-5.0 / JBossWeb-2.1 Set-Cookie:JSESSIONID = XXXXXXXXXXXXXXXXXXXXXXX;路径= / thegateway;安全P3P:CP =“CAO PSA OUR”X-Powered-By:ASP.NET日期:星期六,2011年1月22日00:07:25 GMT

我如何阅读其余内容?

1 个答案:

答案 0 :(得分:0)

也许您忘了在curl调用中设置CURLOPT_RETURNTRANSFER选项? 设置后,curl_exec()函数本身会返回响应的内容。

这是我的一个工作项目的代码:

    $options = array(
            CURLOPT_SSL_VERIFYPEER => false, 

            CURLOPT_RETURNTRANSFER => $this->return_content,     // return web page
            CURLOPT_HEADER         => false,    // don't return headers, they are processed through callback
            CURLOPT_FOLLOWLOCATION => $this->follow_redirects,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_USERAGENT      => $this->user_agent, // who am i
            CURLOPT_CONNECTTIMEOUT => $this->connect_timeout,      // timeout on connect
            CURLOPT_TIMEOUT        => $this->request_timeout,      // timeout on response
            CURLOPT_BINARYTRANSFER => true,
            );
    $extraheaders = array();            

    $res = curl_init( $url );
    curl_setopt_array( $res, $options );
    $content = curl_exec( $res );