【问题标题】:Dynamically adding products to ZenCart via CURL通过 CURL 将产品动态添加到 ZenCart
【发布时间】:2011-11-14 23:36:16
【问题描述】:

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

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

提前致谢

【问题讨论】:

    标签: php authentication dynamic curl zen-cart


    【解决方案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);

    【讨论】:

      猜你喜欢
      • 2023-01-01
      • 2012-11-08
      • 2013-05-07
      • 1970-01-01
      • 2019-12-27
      • 2013-02-14
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多