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