PHP本地CURL正常,但是放到SAE上后出现object moved to here
程序员文章站
2022-04-22 21:41:01
...
login.php
curlajax.class.php
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 ''; $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 = '/"; $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);?>
curlajax.class.php
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 ''; 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 ''; var_dump(curl_getinfo($ch)); } curl_close($ch); return $r; }}
在本地可以正常获取到相应的信息,可放到sae上后总是object moved to here,
SAE上在login.php第49行打印的信息中Location的值是
Location:/(buoezbuq4apeu0v0151ruv55)/zdy.htm?aspxerrorpath=/xs_main.aspx;
而正常也就是在本地得到的正常值应该是
Location: /(buoezbuq4apeu0v0151ruv55)/xs_main.aspx?xh=1011125007
小弟真心对curl中的一些东西了解甚少。。跪求论坛大牛们帮助。。。。
这是我sae上的测试地址:http://1.sdlgwx.sinaapp.com/lg/login.php测试账号:1011125007 密码111111
回复讨论(解决方案)
楼主,你的问题解决了么。。。我跟你是一样一样的问题。。。一模一样