我做了一个创建高分辨率图像的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);
但没有成功。有什么想法吗?
提前感谢
发布于 2011-09-13 19:14:41
尝试使用不同类型的身份验证。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);
https://stackoverflow.com/questions/7382229
复制相似问题