windows上,snoopy好像不支持https,所以决定用curl
我安装的是xampp集成环境,附带有curl
用curl做http模拟登录没有什么问题,但是https就不行,如gmail
想请问各位如何实现curl的https请求,谢谢!
PS:网上找过很多解决方案,还是不行set_time_limit(0);//cookie保存文件
$cookie_jar = tempnam('./tmp', 'cookie');//登录的账号和密码
$post_fields['Email'] = '*************';
$post_fields['Passwd'] = '*******';//模拟登录
$curl = curl_init();curl_setopt($curl, CURLOPT_URL, 'https://www.google.com/accounts/ServiceLogin'); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields); 
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar); //保存cookie
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);$d = curl_exec($curl);curl_close($curl);
//输出登录后的页面
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/accounts/ManageAccount');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar); //读取cookie
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$data = curl_exec($ch);curl_close($ch);//输出页面
print $data;

解决方案 »

  1.   

    CURLOPT_SSL_VERIFYHOST,CURLOPT_SSL_VERIFYPEER
    少这两个。
    你去查查手册,这些参数都是做什么用的。
      

  2.   

    还有,你的web server必须是携带openSSL的版本
      

  3.   

    我重新修改后的代码,但是还是无法显示登录后的界面
    <?php
    set_time_limit(0);//登录的账号和密码
    $login = '*********';
    $password = '*****';$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"http://mail.google.com/mail/");
    curl_setopt($ch, CURLOPT_REFERER, "");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    //curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
    //curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'read_header'));$html = curl_exec($ch);$matches = array();
    $actionarr = array();$action = "https://www.google.com/accounts/ServiceLoginAuth";#parse the login form:
    #parse all the hidden elements of the form
    preg_match_all('/<input type\="hidden" name\="([^"]+)".*?value\="([^"]*)"[^>]*>/si', $html, $matches);
    $values = $matches[2];
    $params = "";$i=0;
    foreach ($matches[1] as $name)
    {
    $params .= "$name=" . urlencode($values[$i]) . "&";
    ++$i;
    }$login = urlencode($login);
    $password = urlencode($password);curl_setopt($ch, CURLOPT_URL, $action);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params ."Email=$login&Passwd=$password&PersistentCookie=");
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);$html = curl_exec($ch);//输出登录后的页面
    print $html;