1

我已经完成了一个创建高分辨率图像的 Flash 应用程序。我正在尝试通过 php 脚本将此图像作为产品添加到 ZenCart。我想通过 curl 访问管理员,添加一个新产品,如果成功,返回新创建的产品 ID。

这将是脚本的登录部分:

$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);

没有成功。有任何想法吗?

提前致谢

4

1 回答 1

1

尝试使用不同类型的身份验证。手册中提到:

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);

于 2011-09-13T19:14:40.893 回答