Heim > Artikel > Backend-Entwicklung > PHP本地CURL正常,但是放到SAE上后出现object moved to here
login.php
<?php error_reporting(E_ALL&~E_NOTICE); set_time_limit(0); include 'curlajax.class.php'; //$proxy = "http://127.0.0.1:8087"; //init curlÀà $man = new curlajax(); $man->debug = 0; $s = new SaeStorage(); $domain='sdlgdm'; $filename='/yzm/'; if($_POST['login']){ $url = 'http://210.44.176.134/(buoezbuq4apeu0v0151ruv55)/Default2.aspx'; $data = '__VIEWSTATE='.urlencode($_POST['stat']).'&txtUserName='.urlencode($_POST['TextBox1']).'&TextBox2='.urlencode($_POST['TextBox2']).'&txtSecretCode='.urlencode($_POST['TextBox3']).'&RadioButtonList1='.urlencode('学生').'&Button1=&lbLanguage=&hidPdrs=&hidsc='; $data = iconv("UTF-8", "GBK", $data); $ch = curl_init(); // $proxy = "http://127.0.0.1:8087"; if($proxy){ echo 'proxy'; curl_setopt ($ch, CURLOPT_PROXY, $proxy); } curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.158888800.95 Safari/537.36 SE 2.X MetaSr 1.0"); curl_setopt($ch,CURLOPT_REFERER,$url); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); /* curl_setopt($ch,CURLOPT_HTTPHEADER,array ( 'Proxy-Connection: keep-alive', 'Cache-Control: max-age=0', 'Origin: http://210.44.176.133', 'DNT: 1', )); */ echo '<pre class="brush:php;toolbar:false">'; $Headers = curl_getinfo($ch); print_r($Headers); $r = curl_exec($ch); curl_close($ch); print_r($r);//die; $pre = 'http://210.44.176.134/'; $pat = "/Location:(.*)/i"; preg_match($pat,$r,$m); $rurl = trim($m[1]); print_r($rurl); $rurl = $pre.''.substr($rurl,1); //location $r = $man->httpget($rurl,$url,0,array(),$proxy); //file_put_contents('main.txt',$r); $pre = 'http://210.44.176.134/(buoezbuq4apeu0v0151ruv55)/'; $pat = '/<a href="(xskbcx[^"]*)"/i'; preg_match($pat,$r,$m); echo "<br/>"; $infourl = trim($m[1]); echo $infourl = $pre.''.$infourl; $r = $man->httpget($infourl,$rurl,0,array(),$proxy); //file_put_contents('info.txt',$r); echo $r; }else{ //login $url = 'http://210.44.176.134/(buoezbuq4apeu0v0151ruv55)/Default2.aspx'; $r = $man->httpget($url,'',1,array(),$proxy); $pat = "/Location:(.*)/i"; preg_match($pat,$r,$m); $rurl = trim($m[1]); //file_put_contents('loginpage.txt',$r); //print_r($r);die; print_r($r);die; //GET __VIEWSTATE $pat = '/name="__VIEWSTATE" value="([^"]*)"/i'; preg_match($pat,$r,$m); $stat = $m[1]; //GET vocde $vocde_url = 'http://210.44.176.134/(buoezbuq4apeu0v0151ruv55)/CheckCode.aspx'; $r = $man->httpget($vocde_url,$url,0,array(),$proxy); $base=base64_encode($r);?><form action="" method="post"><input type="hidden" name="stat" value="<?php echo $stat;?>"/>x h:<input name="TextBox1" type="text" style="Width:130px" /><br />pwd:<input name="TextBox2" type="password" style="Width:130px" /><br />code:<input name="TextBox3" type="text" style="Width:70px;color:#92a4bf" /><img src="data:image/jpg;base64,<?php echo $base? alt="PHP本地CURL正常,但是放到SAE上后出现object moved to here" >" style="max-width:90%" /><br /><input type="submit" name="login" value="submit"/></form><?php}?>
<?phpclass curlajax{ public $ua; public $debug; function __construct(){ $this->debug = 1; $this->ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.158888800.95 Safari/537.36 SE 2.X MetaSr 1.0'; } /**************************** *get 请求资源 *@param string 地址 *@param string referer *@param boolen 是否返回头部 *@param array 头部附加cookie ****************************/ function httpget($url,$referer='',$withhead=1,$httphead = array(),$proxy=''){ $ch = curl_init(); if($proxy){ curl_setopt ($ch, CURLOPT_PROXY, $proxy); } curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiejar); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); curl_setopt($ch,CURLOPT_HEADER,$withhead); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); //curl_setopt($ch,CURLOPT_AUTOREFERER,1); /* curl_setopt($ch,CURLOPT_HTTPHEADER,array ( 'Proxy-Connection: keep-alive', 'Cache-Control: max-age=0', 'Origin: http://210.44.176.133', 'DNT: 1', )); */ curl_setopt($ch,CURLOPT_USERAGENT,$this->ua); curl_setopt($ch,CURLOPT_REFERER,$referer); $r = curl_exec($ch); if($this->debug){ echo '<pre class="brush:php;toolbar:false">'; var_dump(curl_getinfo($ch)); } curl_close($ch); return $r; } /**************************** *post 请求资源 *@param string 地址 *@param string referer *@param array 提交数据 *@param boolen 是否返回头部 ****************************/ function httppost($url,$referer='',$postdata=array(),$withhead=0,$httphead = array(),$proxy=''){ $ch = curl_init(); if($proxy){ curl_setopt ($ch, CURLOPT_PROXY, $proxy); } curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,$withhead); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); //curl_setopt($ch,CURLOPT_AUTOREFERER,1); curl_setopt($ch,CURLOPT_USERAGENT,$this->ua); curl_setopt($ch,CURLOPT_REFERER,$referer); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata); $r = curl_exec($ch); if($this->debug){ echo '<pre class="brush:php;toolbar:false">'; var_dump(curl_getinfo($ch)); } curl_close($ch); return $r; }}
楼主,你的问题解决了么。。。我跟你是一样一样的问题。。。一模一样