我试图登录到网站,然后去一个链接,然后提交一个表单,以获得所需的数据。 我想用卷曲做到这一点。 我已经实现了在洛成功进入该网站。 登录重定向我的个人资料页。
现在我需要遵循一个链接,然后提交表单! 但是当我做到这一点使用curl会话无效。 我得到的JSESSIONID在我用来存储创建cookie的一个cookie.txt文件。 我已经看到了所有的例子都只是洛成一个网站,或只是一个登记表submission.that只是一个单一的POST请求!
我该如何去到另一条链路,然后提交使用curl后,我已经成功登录并存储在cookie的另一种形式?
我使用WAMP作为我的本地服务器。
<?php
$username="myusername";
$password="mypassword";
$url="http://onlinelic.in/LICEPS/Login/webLogin.do";
$referer = "http://onlinelic.in/epslogin.htm";
$postdata = "portlet_5_6{actionForm.userName}=".$username."&portlet_5_6{actionForm.password}=".$password;
$cookie = "cookie.txt" ;
$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,false);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, $referer);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
logIntoLocator();
curl_close($ch);
function logIntoLocator()
{
$pincode = "731234";
$locatorType = "P";
$url = "http://onlinelic.in/LICEPS/appmanager/Customer/CustomerHome?_nfpb=true&_windowLabel=Cust_Agent_Locator_portlet_25_2&Cust_Agent_Locator_portlet_25_2_actionOverride=%2Fportlets%2Fvisitor%2FAgentLocator%2Flocating";
$referer = "https://customer.onlinelic.in/LICEPS/appmanager/Customer/CustomerHome?_nfpb=true&_windowLabel=CustomerLocatorsPortlet_1&_cuid=RC_t_832059&_pagechange=AgentLocator";
$postData = "Cust_Agent_Locator_portlet_25_2wlw-radio_button_group_key:{actionForm.agentRadioOption}=".$locatorType."&Cust_Agent_Locator_portlet_25_2{actionForm.agentOption}=".$pincode;
$cookie = "cookie.txt" ;
$agentCurl = curl_init();
curl_setopt ($agentCurl, CURLOPT_URL, $referer);
curl_setopt ($agentCurl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($agentCurl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
curl_setopt($agentCurl,CURLOPT_COOKIESESSION,true);
curl_setopt ($agentCurl, CURLOPT_TIMEOUT, 60);
curl_setopt ($agentCurl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($agentCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($agentCurl, CURLOPT_REFERER, $referer);
curl_setopt ($agentCurl, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($agentCurl, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($agentCurl, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($agentCurl, CURLOPT_POST, 1);
$result = curl_exec ($agentCurl);
echo $result;
}
如果你想给它一个尝试的用户名是“manashch1”,密码为“nokia1105 *”。 登录那里去AgentLocator和有ü可以输入PIN代码为731234,并获得所需的数据。