dsfdsfsdf45489 2013-09-13 15:07
浏览 67
已采纳

使用curl登录到https网站不工作,怀疑godaddy验证与它有关

I use the following general code to log into other https sites and pull records using forms, but it doesn't seem to work for www.voip.ms. I've created a testing account so if anyone wants to take a crack at it and tell me what I did wrong. (Warning, the site only gives your IP address 4 tries until it bans it)

<?php
ini_set('max_execution_time', 300);
$username="meahmatt@aol.com"; 
$password="testaccount"; 
$url="https://www.voip.ms/m/login.php"; 
$cookie="cookie.txt"; 

$postdata = "col_email".$username."&col_password=".$password."&action=login&form1="; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 
curl_close($ch);
echo $result;
?>

I've also tried setting CURLOPT_SSL_VERIFYPEER, TRUE with no change

  • 写回答

2条回答 默认 最新

  • douluo5937 2014-01-09 09:04
    关注

    I had the same problem recently trying to use the twitter api using curl_exec from godaddy.

    The magic was to disable both peer and host verification in the options :

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // required as godaddy fails
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // required as godaddy fails
    

    The error was a certificate verification problem. I have no problem using this exact script on non-godaddy servers.

    CURLE_SSL_CACERT (60)
    Peer certificate cannot be authenticated with known CA certificates.
    

    The full request looks like this :

      $url = "https://api.twitter.com/1.1/statuses/user_timeline.json?..."
        $headers = array( 
            "Authorization: Bearer ".$bearer."",
        ); 
    
    $ch = curl_init();  // setup a curl
    curl_setopt($ch, CURLOPT_URL, $url);  // set url to send to
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set custom headers
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return data reather than echo
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // required as godaddy fails
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // required as godaddy fails
    
    // $info = curl_getinfo($ch); // debug info
    // var_dump($info); // dump curl info
    
    $result = curl_exec($ch); // run the curl
    
    curl_close($ch);  // stop curling
    
    // Check for errors and display the error message
    if($errno = curl_errno($ch)) { echo "curlerror::$errno::"; }
    

    Also notice that curl_getinfo and curl_errno were invaluable at finding the problem.

    tl;dr , friends don't let friends use godaddy.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答