0
我能够获取GET请求,但在POST和PUT请求中存在与验证有关的问题。我收到错误“您必须先登录才能使用Bugzilla的这一部分”。我提供了正确的用户名和密码。我已经尝试CURLAUTH_ANY以及CURLAUTH_BASIC。我已经尝试了PUT和POST请求。任何帮助表示赞赏。您必须在使用Bugzilla的这部分代码之前登录,代码:410
$url ="http://localhost:8080/bugzilla/rest/bug/2";
$apikey = "IZC4rs2gstCal0jEZosFjDBRV9AQv2gF0udh4hgq";
$data = array(
"product" => "TestProduct",
"component" => "TestComponent",
"version" => "unspecified",
"summary" => "This is a test bug - please disregard",
"alias" => "SomeAlias",
"op_sys" => "All",
"priority" => "P1",
"rep_platform" => "All"
);
$str_data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$str_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type: application/json", "Accept: application/json"));
$username = '[email protected]';
$password = 'abbincrc';
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $result
您正在声明API密钥变量但未使用它。 – jedifans
'localhost:8080'? – RamRaider
localhost:8080是正确的(没有问题,因为我的Bugzilla被配置为在端口8080运行)。我可以从浏览器调用它,一切正常,我没有使用API密钥,我刚刚宣布它(我只是试验)。我在网上看到的例子不需要API密钥,只有用户名和密码就足够了。感谢您的评论 – user1468768