登录Channel Advisor

时间:2012-06-04 06:59:27

标签: php curl

我正在尝试登录频道顾问,但输出错误: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] = 'username=xxxxx@gmail.com&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); 

3 个答案:

答案 0 :(得分:0)

如果您正在寻找来自'https://merchant.channeladvisor.com/AM/MyInventory/View_Inventory.aspx'的数据,为什么不使用API​​呢?

http://developer.channeladvisor.com/display/cadn/Inventory+Service

答案 1 :(得分:0)

如果您想要做的只是导出库存信息,ChannelAdvisor有自己的UI可用库存导出服务。至少,您可以自动化代码以启动它并下载导出的csv或制表符分隔文件:http://ssc.channeladvisor.com/howto/exporting-inventory

答案 2 :(得分:-1)

我认为您应该从Channel Advisor处理此类更新,因此请遵循重定向。

由于我不认为这是使用curl登录Channel Advisor的常用方法,因此您始终需要在每次Channel Advisor更新时更新代码。 当我们只能使用curl检索Google Analytics数据时,它会记住我:每次更新登录系统时,都必须重写自己的curl登录方法 - 无聊

关于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]); ,您可以阅读this answer。基本上是:

{{1}}