2012-06-04 82 views
0

我在嘗試登錄渠道顧問,但輸出的錯誤爲:HTTP/1.1 302 Moved Temporarily登錄到渠道顧問

但上週它運行完美,我登錄和檢索我的數據,現在我再次運行它有一個錯誤。

這裏是我的代碼:

$pages = array('home' => 
'https://login.channeladvisor.com/?gotourl=https%3a%2f%2fcomplete.channeladvisor.com%2f', 
      'login' => 
'https://login.channeladvisor.com/?gotourl=https%3a%2f%2fcomplete.channeladvisor.com%2f', 
      'data' => 
    'https://merchant.channeladvisor.com/AM/MyInventory/View_Inventory.aspx?apid=32001263'); 

    $ch = curl_init(); 
    //Set options for curl session 
    $options = array(CURLOPT_USERAGENT => 'Mozilla/12.0 (compatible; MSIE 6.0; Windows NT 5.1)', 
     CURLOPT_SSL_VERIFYPEER => FALSE, 
     CURLOPT_SSL_VERIFYHOST => 2, 
     CURLOPT_HEADER => TRUE, 
     CURLOPT_RETURNTRANSFER => TRUE, 
     CURLOPT_COOKIEFILE => 'cookies.txt', 
     CURLOPT_COOKIEJAR => 'cookies.txt'); 

//Hit home page for session cookie 
$options[CURLOPT_URL] = $pages['home']; 
curl_setopt_array($ch, $options); 
//curl_exec($ch); 

//Login 
$options[CURLOPT_URL] = $pages['login']; 
$options[CURLOPT_POST] = TRUE; 
$options[CURLOPT_POSTFIELDS] = '[email protected]&password=xxxxxxx'; 
$options[CURLOPT_FOLLOWLOCATION] = false; 
curl_setopt_array($ch, $options); 
curl_exec($ch); 

//Hit data page 
$options[CURLOPT_URL] = $pages['data']; 
curl_setopt_array($ch, $options); 
$data = curl_exec($ch); 

//Output data 
echo $data; 

//Close curl session 
curl_close($ch); 

回答

-1

我想你應該從頻道顧問處理這類更新,因此,跟蹤重定向。

因爲我不認爲這是使用curl登錄Channel Advisor的常用方式,所以您將需要隨時更新每個Channel Advisor更新中的代碼。 它記得我只能使用curl檢索Google Analytics數據:每次更新登錄系統時,都必須重新編寫自己的捲曲登錄方法 - 無聊

你可以閱讀this answer關於跟隨一個Header: Location與捲曲。基本上是:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$a = curl_exec($ch); 
if(preg_match('#Location: (.*)#', $a, $r)) 
$l = trim($r[1]);