本文介绍了没有反应与Curl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用curl将我的用户ID和密码传递到www.licindia.in网站,但我遇到了cookie的问题,也许,我无法继续我的会话和网站响应302错误,文档已经暂时移动,现在我没有得到这个代码的反应: -

I am trying to pass my userid and password to the site www.licindia.in using curl, but I am getting trouble with cookies perhaps, I am unable to continue my session and the site response 302 error, the document has been moved temporarily, now I am getting no response with this code :-

<?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;
    }
?>


推荐答案

您已指定不愿意使用此语句的任何重定向:

You have specified that you're not willing to follow any redirects with this statement:

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);

将值设置为更高或不指定它将使cURL跟随重定向。

Setting the value higher or not specifying it will make cURL follow redirects.

这篇关于没有反应与Curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:38