通过 CURL 动态添加产品到 ZenCart
我已经完成了一个创建高分辨率图像的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用不同类型的身份验证。 手册提到:
因此,我会选择
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:
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);