2011-09-12 43 views
1

我已經完成了一個創建高分辨率圖像的Flash應用程序。我試圖通過php腳本將此圖像作爲產品添加到ZenCart中。我想通過curl訪問管理員,添加一個新產品,如果成功,返回新創建的產品ID。通過CURL動態添加產品到ZenCart

這將是腳本的登錄部分:

$curl = curl_init(); 
$fields = array('admin_name'=>'user', 'admin_pass'=>'pass'); 
$url = 'http://www.mystore.com/login.php'; 

curl_setopt($curl, CURLOPT_POST,  1); 
curl_setopt($curl, CURLOPT_URL,   $url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);       
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields); 

$result = curl_exec($curl); 

if(curl_errno($curl)){ 
    echo 'error'; 
} else { 
    echo $result; 
} 

可惜我只收到以下錯誤信息:

Authorization Required 

This server could not verify that you are authorized to access the document requested.  Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't  understand how to supply the credentials required. 

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. 

我已經嘗試使用

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 

沒有成功。有任何想法嗎?

在此先感謝

回答

1

嘗試使用不同類型的身份驗證。 manual提及:

CURLAUTH_ANY是CURLAUTH_BASIC的別名| CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM。

所以我會去要麼curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

,或者如果不工作或不支持嘗試:

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM);