Curl没有回应

问题描述:

我试图通过我的用户名和密码到www.licindia.in使用卷曲,但我得到的cookies也许,我无法继续我的会议和网站响应302错误,该文件已被临时移动,现在我得到这个代码没有任何反应: -Curl没有回应

<?php 
    $username="myusername"; 
    $password="password"; 
    $url="http://onlinelic.in/LICEPS/Login/webLogin.do"; 
    //echo "praveenpuglai"; 
    $postdata = "portlet_5_6{actionForm.userName}=".$username."&portlet_5_6{actionForm.password}=".$password; 
    $cookie = "JSESSIONID"; 
    ch = curl_init(); 
    curl_setopt ($ch, CURLOPT_URL, $url); 
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true); 
    curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0"); 
    curl_setopt($ch,CURLOPT_COOKIESESSION,true); 
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_REFERER, $url); 
    //var_dump($ch); 
    curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
    curl_setopt ($ch, CURLOPT_POST, 1); 
    // $result = curl_exec ($ch); 
    //echo $result; 
    /*if($result != null) 
    { 
    header('Location: http://onlinelic.in/LICEPS/appmanager/Customer/CustomerHome'); 
    } */ 
// curl_close($ch); 
    $response = curl_exec($ch); 
    $info = curl_getinfo($ch); 
    curl_close($ch); 
    if($info['http_code'] == 301 || $info['http_code'] == 302) { 
     preg_match_all('|Location: (.*)\n|U', $response, $results); 
     $location = implode(';', $results[1]); 
     header("Location: $location"); 
     exit; 
    } else { 
     $response = substr_replace($response, '', 0, strpos($response, '<', 0)); 
     echo $response; 
    } 
?> 

你指定了你不愿意遵循任何重定向有这样的说法:

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 

设置值越高或不指定它会使cURL遵循重定向。

+0

感谢您的答复,现在我能够登录,但还是老样子无法使用导致未经授权的访问的帐户,我觉得还是Cookie不会存储,我已经使用CURLOPT_COOKIEJAR存储在cookie中的卷曲产生的cookies .txt但我不知道为什么它不工作。 – avinashse

+0

在同一个cURL会话中cookie已经自动保存;当你使用'curl_init()' –

+0

创建一个新的实例时,你只需要一个cookie jar文件嗯......我使用cookie jar文件调用cookie.txt来存储cookie信息,并且还使用COOKIEFILE将该信息发送回服务器但这是行不通的。 '$ cookie =“cookie.txt” curl_setopt($ ch,CURLOPT_COOKIEJAR,$ cookie); curl_setopt($ ch,CURLOPT_COOKIEFILE,$ cookie); ' – avinashse

<?php 
    $username="XXXXXX"; 
    $password="YYYYYY"; 
    $url="url"; 
    $capt="ZZZZZ"; 




    $postdata = "?{actionForm_userName}=".$username."&{actionForm_password}=".$password."&{actionForm_qreply}=".$capt; 
    $cookie = "JSESSIONID"; 

    $ch = curl_init(); 
    curl_setopt ($ch, CURLOPT_URL, $url); 

    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0"); 
    curl_setopt($ch,CURLOPT_COOKIESESSION,true); 
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 

    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt ($ch, CURLOPT_HEADER, 0); 
    curl_setopt ($ch, CURLOPT_REFERER, $url); 
    curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
    curl_setopt ($ch, CURLOPT_POST, 1); 

     //echo $cookie; 
     //echo $postdata; 
echo curl_error($ch); 
    $result = curl_exec ($ch); 
    print($result); 


curl_close($ch); 


    $response = curl_exec($ch); 
    $info = curl_getinfo($ch); 
    curl_close($ch); 
    if($info['http_code'] == 301 || $info['http_code'] == 302) { 
     preg_match_all('|Location: (.*)\n|U', $response, $results); 
     $location = implode(';', $results[1]); 
     header("Location: $location"); 
     exit; 
    } else { 
     $response = substr_replace($response, '', 0, strpos($response, '<', 0)); 
     echo $response; 
    } 

?>