通过 CURL 动态添加产品到 ZenCart

发布于 2024-12-03 22:55:09 字数 1155 浏览 1 评论 0原文

我已经完成了一个创建高分辨率图像的 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);

但没有成功。有什么想法吗?

提前致谢

I've done a flash app that creates an high res image. I'm trying to dinamically add this image as a product to ZenCart, via a php script. I thought of accessing the admin via curl, adding a new product and, if successful, returning the newly created product ID.

This would be the login part of the script:

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

but unfortunately I'm only getting the following error message:

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.

I've tried using

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

with no success. Any ideas?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行至春深 2024-12-10 22:55:09

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

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

因此,我会选择 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

或者如果这不起作用或不受支持,请尝试:

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

Try using different types of authentication. The manual mentions:

CURLAUTH_ANY is an alias for CURLAUTH_BASIC | CURLAUTH_DIGEST |
CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM.

So I would go for either curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

or if that doesn't work or isn't supported try:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文