$cookie_file = tempnam(SAE_TMP_PATH, 'cookie'); //用于保存cookie在sae $ch=curl_init("http://教务地址/default2.aspx"); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //禁止重定向 curl_setopt($ch, CURLOPT_TIMEOUT,1000); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); $str=curl_exec($ch); $info=curl_getinfo($ch); curl_close($ch); $pattern = '/<input type="hidden" name="__VIEWSTATE" value="(.*?)" \/>/i'; preg_match($pattern, $str, $matches); $view = urlencode($matches[1]); $login_url="http://教务地址/default2.aspx"; $login="__VIEWSTATE={$view}&TextBox1={$jwid}&TextBox2={$jwpwd}&RadioButtonList1=%D1%A7%C9%FA&Button1=&lbLanguage="; //用于提交登录数据 $ch=curl_init(); curl_setopt($ch, CURLOPT_URL,$login_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT,1000); curl_setopt($ch, CURLOPT_POSTFIELDS, $login); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); $str=curl_exec($ch); //到这里已经登录成功,强调 echo $str 也不会显示登录成功后的页面 curl_close($ch);
发表评论: