使用 curl 登录


Sign in with curl

>我试过了,但我无法使用以下代码登录。执行后,我再次显示登录页面。有人可以帮助我吗?

$tmp_fname = tempnam("/tmp", "COOKIE");
 $curl_handle = curl_init ("https://accessmanager.thy.com/amserver/UI/Login?goto=http%3A%2F%2Fwww2.thy.com%3A80%2Fuhkm");
 curl_setopt ($curl_handle, CURLOPT_COOKIEJAR, $tmp_fname);
 curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, true);
 $post_array = array('gx_charset' => 'UTF-8','encoded' => 'true', 'goto' => 'aHR0cDovL3d3dzIudGh5LmNvbTo4MC91aGtt','IDToken1' => 'XXXXXXXX', 'IDToken2' => 'XXXXXXXX');
 curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post_array);
 $output = curl_exec ($curl_handle);
 $curl_handle = curl_init ("https://accessmanager.thy.com/amserver/UI/Login");
 curl_setopt ($curl_handle, CURLOPT_COOKIEFILE, $tmp_fname);
 curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

 $output = curl_exec ($curl_handle);
 echo $output;  

还需要遵循重定向:

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);